Articles → Android → Interaction with internal storage in android

Interaction with internal storage in android














Example
















public void WriteInInternalStorage(View view) {
	EditText name = (EditText) findViewById(R.id.name);
	String data = name.getText().toString();

	try {
		FileOutputStream outputFileStream = openFileOutput("file.txt", Context.MODE_PRIVATE);
		outputFileStream.write(data.getBytes());
		outputFileStream.close();
	} catch(Exception e) {
		e.printStackTrace();
	}
}

public void ClearData(View view) {
	EditText name = (EditText) findViewById(R.id.name);
	name.setText("");
}

public void DeleteInternalStorageFile(View view) {
	this.deleteFile("file.txt");
}

public void ReadFromInternalStorage(View view) {
	EditText name = (EditText) findViewById(R.id.name);
	try {
		InputStream inputStream = this.openFileInput("file.txt");
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

		String line = new String();
		String allLines = new String();

		while ((line = bufferedReader.readLine()) != null) {
			allLines += line;
		}

		name.setText(allLines);
		inputStream.close();
	} catch(Exception e) {
		e.printStackTrace();
	}
}






Picture showing the screen on load

Click to Enlarge



Picture showing the Write button for writing data in the internal storage in android

Click to Enlarge



Picture showing the Clear button for clearing data from the textbox

Click to Enlarge



Picture showing the Read button for reading data from the internal storage in android

Click to Enlarge


How can we see the file in internal storage?








Picture showing the file in the internal storage in android

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 25, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250