【发布时间】:2018-10-09 21:55:12
【问题描述】:
我正在尝试在代号 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 类时,它可以完美运行(它仅在我运行 mainclass 时才有效)但是当我构建项目时,构建失败并且输出显示此错误:
`C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:8: 错误:找不到符号导入 java.io.File;符号:类文件 位置:包java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:9: 错误:找不到符号导入 java.io.FileInputStream;符号:
类 FileInputStream 位置:包 java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:10: 错误:找不到符号导入 java.io.FileNotFoundException;
符号:类 FileNotFoundException 位置:包 java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:11: 错误:找不到符号导入 java.io.FileOutputStream;符号:
类 FileOutputStream 位置:包 java.io C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:25: 错误:找不到符号 抛出 FileNotFoundException,IOException 符号:类 FileNotFoundException 位置:类 NewMain C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java:38: 错误:找不到符号 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: 错误:找不到符号 os = new FileOutputStream(符号:类 FileOutputStream 位置:类 ServiceEquipe 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")); 符号:类 FileInputStream 位置:类 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")); 符号:类文件位置:类NewMain C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:32: 错误:找不到符号 os = new FileOutputStream(new File("C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png"));符号:等级 FileOutputStream 位置:NewMain 类 C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompany\gui\NewMain.java:32: 错误:找不到符号 os = new FileOutputStream(new File("C:/wamp64/www/PiWeb1/TeamFlags/mpmppp.png"));符号:等级 文件位置:NewMain 类注意: C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java 使用或覆盖已弃用的 API。注意:重新编译 -Xlint:deprecation 了解详情。注意:C:\Users\Emel\Documents\NetBeansProjects\PIMOBILE\Mobile\src\com\mycompagny\Service\ServiceEquipe.java 使用未经检查或不安全的操作。注意:重新编译 -Xlint:详细信息未选中。 11 个错误
`
现在我需要将该代码块放入一个方法中来调用它,我尝试以不同的方式做到这一点,但我失败了,它只有在我在主类中使用时才有效。
PS1:当我从项目中删除该主类时,构建成功。
PS2:该解决方案在普通的 java 项目中完美运行,所以我认为问题是由于代号 One。
我正在使用 netbeans。
【问题讨论】:
标签: java file-io copy codenameone java-io