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();
	}
}







Click to Enlarge




Click to Enlarge




Click to Enlarge




Click to Enlarge


How can we see the file in internal storage?









Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250