This is driving me insane because it should be working. I'm trying to write two string arraylist to a file. Keep in mind I'm writing to internal storage, so manifest permissions are not the issue here. Here is my code:
File cacheFile = new File(context.getFilesDir(), getChannelFile(s[0]) + ".cache"); if (!cacheFile.exists()) { try { FileWriter out = new FileWriter(cacheFile); for (int i = 0; i < titleArray.size(); i++) { Log.d(timesArray.get(i), titleArray.get(i)); out.write(timesArray.get(i) + "#" + titleArray.get(i)); out.write(System.getProperty("line.separator")); } out.close(); } catch (Exception e) { Log.e(Ids.TAG, e.getMessage()); } } Logcat shows exactly what I want to write. But it doesn't write to the file. After this code is executed, my file is created but is 0 bytes. I'm at a loss because there are no exceptions caught and my Log.d shows everything is correct. What am I missing here?
out.flush()before closing the writer.out.flush()did not work.cacheFileobject.out.flush()right above theout.close()but after putting theout.flush()within theforloop, it worked. Thanks!out.flush(); out.close();unless you are getting an exception. Try putting the two into thefinallyblock.