I want to read every character in a text file. For example I have a text file which contains the following text “John 26 Canada” and I want to read every Character so that I can put each String into its specific text view. This would be the output.
Name : John
Age : 26
Country : Canada
I have this code in saving data into text file.
private void performSaveFile(String f) {
// this does the actual file saving.
// set the filename in the interface:
EditText name = (EditText) findViewById(R.id.etName);
EditText age = (EditText) findViewById(R.id.etAge);
EditText country = (EditText) findViewById(R.id.etCountry);
String strFileContent = name.getText().toString()
+ age.getText().toString() + country.getText().toString();
// ... and save the file:
try {
FileOutputStream oStream = openFileOutput(f, Context.MODE_PRIVATE);
oStream.write(strFileContent.getBytes());
oStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream oStream = openFileOutput(f, Context.MODE_PRIVATE);
oStream.write(strFileContent.getBytes());
oStream.close();
above is your code , now you have taken f as string it should be File name.Code goes like this…