时间:2020-10-06 21:56:18 | 栏目:JAVA代码 | 点击:次
用Scanner输入,用PrintStream输出
功能:从in.txt读入,输出到out.txt
代码:
和下面的一样
package ioTest; import java.io.*; import java.util.Scanner; public class TestMain { public static void main(String[] args) { try { Scanner sc=new Scanner(new File("in.txt")); PrintStream ps=new PrintStream("out.txt"); while(sc.hasNext()){ int a=sc.nextInt(); System.out.print(a+" "); ps.println(a); } } catch (Exception e) { e.printStackTrace(); } } }
结果: