I use a read and write line to internal memory. My "WriteFavData" is working fine. But in "ReadFavData" does not work. In fact, when I reach the line , if (favFile.exists ()) is in ReadFavData (.., ..), it says that the file is not found and does not execute the else part. I already checked the internal memory of the emulator using the command line shell accessible by adb shell cat / data / data / com.android.mypackage / files / fav_data_channel , there is a file. Why is it said that the file is missing.? Any ideas ....
public boolean ReadFavData(Context context, String channelName) { boolean isFileFound = false; FileInputStream fin ; StringBuffer strContent = new StringBuffer(""); String fileName = FAV_FILE_NAME + "_" + channelName; File favFile = new File(fileName); int ch; if(favFile.exists()) { isFileFound = true; try { fin = context.openFileInput(FAV_FILE_NAME + "_" + channelName); isFileFound = true; while ((ch = fin.read()) != -1) { strContent.append((char) ch); } fin.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Log.i(TAG, "not found"); } return isFileFound; } public boolean WriteFavData(Context context, String channelName) { String favStr; FileOutputStream fos ; JSONObject videos = new JSONObject(); videos.put("videos", favJsonArray); String favStr = videos.toJSONString(); //note.toString(); String fileName = FAV_FILE_NAME + "_" + channelName; File f = new File(fileName); if(f.exists()) { Log.i("Old FIle", "Found"); f.delete(); } if(f.exists()) Log.i("Still", "Exist"); try { fos = context.openFileOutput(FAV_FILE_NAME + "_" + channelName, Context.MODE_PRIVATE); fos.write(favStr.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }
Actually, I again debugged and tracked that in the line if (file.exists ()) , the file is missing. But if I comment on this line and read my file directly, it is for them to successfully read the file. What happened to if (file.exists ()) ?
Microeyes
source share