Open Save UTF-8 File To String Java Android Code

String sFileContent = readFile("myfile.txt",StandardCharsets.UTF_8);
	static String readFile(String path, Charset encoding) 
		  throws IOException 
		  byte[] encoded = Files.readAllBytes(Paths.get(path));
		  return encoding.decode(ByteBuffer.wrap(encoded)).toString();
// write file
String sOut = "text blah hello world etc.";
	static void writeToFile(String sB,String name) {
		String folder = ("c:\\folder\\");
		File f = new File(folder+ name);
		BufferedWriter writer = null;
			writer = new BufferedWriter( new OutputStreamWriter(
                           new FileOutputStream( folder+name),"UTF-8"));
			writer.write( sB);
				if ( writer != null)
					writer.close( );
This entry was posted in Android Examples Code and tagged . Bookmark the permalink.

Comments are closed.