I am using Java to create a file with some data in it. But I encouter a problem. Indeed I succeed in creating a file and write "hello" in it when I run from Eclipse. But when I export that code in a jar file and I tried to execute it in the command line (java -jar myappli.jar), the file is not created. I don't understand why.
Here is my java file which is quite simply.
If you have any answers I would be happy to have it :) Thank you.
package testjar;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class Main {
public static void main(String[] args)
{
FileOutputStream f = null;
try
{
f = new FileOutputStream(new File("Export_XML.xml"));
System.setOut(new PrintStream(f));
System.out.println("hello");
}
catch(java.io.IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if(f!=null)
f.close();
}
catch(IOException e) {e.printStackTrace();}
}
}
}