I'm writing my little app for Android. I'm trying to create files. Here is a code snippet:
final String TESTSTRING = new String("Hello Android");
FileOutputStream fOut = openFileOutput("samplefile.txt",Context.MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(TESTSTRING);
osw.flush();
osw.close();
FileInputStream fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
char[] inputBuffer = new char[TESTSTRING.length()];
isr.read(inputBuffer);
String readString = new String(inputBuffer);
boolean isTheSame = TESTSTRING.equals(readString);
if(isTheSame) {
TextView mLat=(TextView) findViewById(R.id.textView1);
mLat.setText(String.valueOf(isTheSame));
}
I can't find this created samplefile.txt using file manager. Can anyone tell me the path where app is writing?
ok now i have this:
String pathToExternalStorage = Environment.getExternalStorageDirectory().toString();
File appDirectory = new File(pathToExternalStorage + "/" + "testowa", "new_file.txt");
try{
OutputStream os = new FileOutputStream(appDirectory);
os.write(pathToExternalStorage.getBytes());
os.flush();
os.close();
}
catch(IOException e)
{
}
Exception Thrown on OutputStream os = new FileOutputStream(appDirectory); Cant find why. i modified manifest with permissions