File open read to StringBuilder close Java example

BufferedReader , FileReader, StringBuilder , readLine, close Java example

Android example

String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
	int c; String sText = "";
	while((c=fis.read())!=-1)
	{
 
		sText += (char)c; // convert int to char
	 }
	fis.close();

Java example

try {
	    BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
	    StringBuilder strBuilder = new StringBuilder();
	    String str;
	    while ((str = in.readLine()) != null) {
	       strBuilder.append(str);
	    }
	    in.close();
	} catch (IOException e) {
		e.toString();
	}
This entry was posted in Android Examples Code and tagged , , , , , . Bookmark the permalink.


Comments are closed.



7,283 views