I'm trying to copy an image with java in a codename One project , this is the code which gives correct copy of the image:
/*
* 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);
}
}
}
the code works perfectly when i put it in a main java class (it only works when i run the mainclass ) but when i build the project the build fails and the output show this error :
`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
`
Now i need to put that code block into a method to recall it, i tried to do that in different ways but i failed it only works when i use it in a main class.
PS1: when i delete that main class from my project the build succeed.
PS2: the solution works perfectly in a normal java project so i think the problem is due to codename One.
Im using netbeans.