IO streams flow InputStreamReader --- 12 --- conversion technology porter (still Silicon Valley)

InputStreamReader the input byte stream into a character stream input

@Test
public void test1(){
	InputStreamReader isr = null;
	try {
		// input stream of bytes
		FileInputStream fis = new FileInputStream ( "Water Margin .txt");
		// byte character input stream into the input stream
		isr = new InputStreamReader(fis);
		char[] cbuf = new char[10];
		int len;
		while ((len = isr.read(cbuf)) != -1) {
			String string = new String(cbuf, 0, len);
			System.out.print(string);
		} 
	} catch (Exception e) {
		e.printStackTrace ();
	} finally {
		if(isr != null) {
			try {
				isr.close();
			} catch (IOException e) {
				e.printStackTrace ();
			}
		}
	}
}

  

 

Guess you like

Origin www.cnblogs.com/noyouth/p/11727810.html
Recommended