I saved the runnable JAR file to another directory (not in the project folder). Now, I can read data from the runnable JAR file, but I can't write any data in file.
Code for reading data:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader()
.getResourceAsStream("TaskList.txt")));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null) {
sb.append(line + "\n");
textArea.setText(sb.toString());
}
reader.close();
}
catch(Exception ex) {
JOptionPane.showMessageDialog(null, "File Not Found");
}
Code for writing data:
try{
String content = textArea.getText();
Writer writer = new OutputStreamWriter(new FileOutputStream("bin/TaskList.txt"));
writer.write(content);
writer.close();
}
catch(Exception ex) {
}