In the following code, I first created a File
in the root directory and then write
string into it. Then I read data from that File
:
File file = new File("myfile.txt");
if(!file.exists()){
file.createNewFile();
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(com_port_hardcoded);
bw.close();
}
Scanner scn = new Scanner(file);
comPort = scn.nextLine().trim();
scn.close();
Now, when I compile and run this code in eclipse, it works perfectly. But when I export a 'runnable jar' of this code, the txt
file is not there in the folder of the jar.
I don't know where the txt
file is generated or if it is generated at all.