try { File file = new File(filePath+\"usedcommands.txt\"); if (!file.exists()) { file.createNewFile();
Use this it will work
fw = new FileWriter("fileName",true);
for more details on FileWriter see this
Pass true as a second argument to FileWriter to turn on "append" mode.
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);