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