Java - 代号一:找不到符号 fileInput/Output

Java - CodeName One: not finding symbole fileInput/Output

我正在尝试在代号 One project 中复制带有 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 class 中时,代码工作得很好(它只在我 运行 主 class 时有效)但是当我构建项目构建失败并且输出显示此错误:

`C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:8: error: cannot find symbol import java.io.File; symbol: class File location: package java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:9: error: cannot find symbol import java.io.FileInputStream; symbol:
class FileInputStream location: package java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:10: error: cannot find symbol import java.io.FileNotFoundException;
symbol: class FileNotFoundException location: package java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:11: error: cannot find symbol import java.io.FileOutputStream; symbol:
class FileOutputStream location: package java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:25: error: cannot find symbol throws FileNotFoundException, IOException symbol: class FileNotFoundException location: class NewMain C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java:38: error: cannot find symbol is = new FileInputStream("C:/Users/Emel/AppData/Local/Temp/temp8255862222083205111..png"); symbol: class FileInputStream location: class ServiceEquipe C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java:39: error: cannot find symbol os = new FileOutputStream( symbol: class FileOutputStream location: class ServiceEquipe C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:31: error: cannot find symbol 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: error: cannot find symbol is = new FileInputStream(new File("C:/Users/Emel/AppData/Local/Temp/temp8255862222083205111..png")); symbol: class File location: class NewMain C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:32: error: cannot find symbol os = new FileOutputStream(new File("C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png")); symbol: class FileOutputStream location: class NewMain C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:32: error: cannot find symbol os = new FileOutputStream(new File("C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png")); symbol: class File location: class NewMain Note: C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 11 errors

`

现在我需要将该代码块放入一个方法中以调用它,我尝试以不同的方式做到这一点,但我失败了,它仅在我在主 class 中使用它时才有效。

PS1:当我从项目中删除主 class 时,构建成功。

PS2:该解决方案在正常的 java 项目中完美运行,所以我认为问题出在代号 One。

我正在使用 netbeans。

java.io.File, java.io.FileInputStream, java.io.FileNotFoundException & java.io.FileOutputStream 在代号一中不存在。

解释很长here

有多种原因,但这些特定的 API 无法在您的应用需要 运行 与其他进程隔离并且具有 limited/restricted 的移动设备上正常运行使用权。例如。在您的情况下,很明显 C: 路径不会存在于 Android 或 iOS 上,这两个都是 Unix 衍生产品(Linux/BSD)。

您需要使用 FileSystemStorageStorage the developer guide.

中有一节是关于这些的