标签:new dex 控制 刷新 nbsp puts fileinput pack not
打印流
1.PrintStream:缓冲字节输出流
2.PrintWriter:缓冲字符输出流
package file; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; import org.junit.Test; /* 1.System中的IO流 System.in:InputStream System.out:PrintStream,默认打印到控制台 System.err:PrintStream PrintStream: (1)不会抛异常 (2)自动刷新 其他IO流,可以手动刷新 */ public class test12 { @Test public void test3() throws FileNotFoundException { System.setIn(new FileInputStream("resource/1.txt")); Scanner input=new Scanner(System.in); System.out.println(input.nextLine()); System.out.println(input.nextLine()); input.close(); } @Test public void test2() throws FileNotFoundException { System.setOut(new PrintStream("resource/1.txt")); System.out.println("hello"); System.out.println("java"); } @Test public void test1() { System.out.println(); //System.out.print(); 必须有参数 } }
package file; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; import org.junit.Test; public class test11 { @Test public void test01() { Scanner s=new Scanner(System.in); System.out.println("input: "); String str=s.next(); System.out.println("input: "+str); } @Test public void test02() throws FileNotFoundException { Scanner input=new Scanner(new FileInputStream("resource/1.txt")); while(input.hasNextLine()) { String line=input.nextLine(); System.out.println(line); } } }
标签:new dex 控制 刷新 nbsp puts fileinput pack not
原文地址:https://www.cnblogs.com/hapyygril/p/13050561.html