首页 文章

Java - CodeName一:找不到symbole fileInput / Output

提问于
浏览
1

我试图用代号为One的项目复制一个带有java的图像,这是给出图像正确副本的代码:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.gui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
 *
 * @author Emel
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
          throws FileNotFoundException, IOException 
    {
        // TODO code application logic here

    InputStream is = null;
        OutputStream os = null;
            is = new FileInputStream(new File("C:/Users/Emel/AppData/Local/Temp/temp8255862222083205111..png"));
            os = new FileOutputStream(new File("C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png"));
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
    }

}

当我把它放在一个主java类(它只在我运行mainclass时工作)时,代码工作得很好但是当我构建项目时,构建失败并且输出显示此错误:

`C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:8:error:找不到符号import java.io.File;符号:class文件位置:包java.io C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:9:error:找不到符号import java.io.FileInputStream ;符号:类FileInputStream位置:包java.io C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:10:错误:找不到符号导入java.io.FileNotFoundException ;符号:class FileNotFoundException location:package java.io C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:11:error:找不到符号import java.io.FileOutputStream ;符号:类FileOutputStream位置:包java.io C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:25:error:找不到符号抛出FileNotFoundException,IOException符号: class FileNotFoundException location:class NewMain C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompagny \ Service \ ServiceEquipe.java:38:error:找不到符号is = new FileInputStream(“C:/ Users” /Emel/AppData/Local/Temp/temp8255862222083205111..png“);符号:类FileInputStream位置:类ServiceEquipe C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompagny \ Service \ ServiceEquipe.java:39:error:找不到符号os = new FileOutputStream(symbol:class FileOutputStream位置:类ServiceEquipe C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:31:error:找不到符号is = new FileInputStream(new File(“C: /Users/Emel/AppData/Local/Temp/temp8255862222083205111..png“)); symbol:class FileInputStream location:class NewMain C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:31:错误:找不到符号is = new FileInputStream(new File(“C:/Users/Emel/AppData/Local/Temp/temp8255862222083205111..png”)); symbol:class文件位置:class NewMain C :\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:32:error:找不到符号os = new FileOutputStream(new file(“C:/ wamp64 / www / PiWe” B1 / TeamFlags / mpmppp.png“));符号:类FileOutputStream位置:类NewMain C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompany \ gui \ NewMain.java:32:error:找不到符号os = new FileOutputStream(new File( “C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png”)); symbol:class文件位置:类NewMain注意:C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompagny \ Service \ ServiceEquipe.java使用或覆盖不推荐使用的API . 注意:使用-Xlint重新编译:弃用以获取详细信息 . 注意:C:\ Users \ Emel \ Documents \ NetBeansProjects \ PIMOBILE \ Mobile \ src \ com \ mycompagny \ Service \ ServiceEquipe.java使用未经检查或不安全的操作 . 注意:使用-Xlint重新编译:取消选中以获取详细信息 . 11个错误

`

现在我需要将该代码块放入一个方法来调用它,我试图以不同的方式做到这一点,但我失败它只有当我在主类中使用它时才有效 .

PS1:当我从我的项目中删除该主类时,构建成功 .

PS2:该解决方案在普通的java项目中完美运行,所以我认为问题是由于代号为One .

我正在使用netbeans .

1 回答

  • 1

    Codename One中不存在 java.io.File, java.io.FileInputStream, java.io.FileNotFoundException & java.io.FileOutputStream .

    有一个很长的解释here .

    有几个原因,但这些特定的API在移动设备上正确运行,您的应用需要与其他进程隔离运行并且访问受限/受限制 . 例如 . 在你的情况下,很明显 C: 路径不会存在于Android或iOS上,这两种路径都是Unix衍 生产环境 品(Linux / BSD) .

    你需要使用 FileSystemStorageStorage 有关于the developer guide中的那些部分 .

相关问题