I m using read & write string to internal memory. My "WriteFavData" is working fine. But In "ReadFavData" is not working. Actually when i reach the line if(favFile.exists()) in ReadFavData(..,..), it says file not found & execute the else part. I have already check the emulator internal memory using command line shell access adb shell cat /data/data/com.android.mypackage/files/fav_data_channel, the file is there. Why is saying file is not present.? 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 debugged again & track that on line if(file.exists()), the file is not present.. But if i comment this line & read my file directly, i m able to read file successfully. Whats wrong with if(file.exists())?