java-打印流
printStream

 
public class Demo99 { public static void main(String[] args) throws FileNotFoundException { PrintStream ps = new PrintStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt"); ps.write(97);//文件里面是a字母 ps.println(97);//97 ps.close(); } }
System.setOut改变输出语句的目的地

public class Demo99 { public static void main(String[] args) throws FileNotFoundException { System.out.println("控制台"); PrintStream ps = new PrintStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt"); System.setOut(ps); System.out.println("输出目的弟"); ps.close(); } } /* 控制台输出“控制台” 文件会写入:“输出目的地” */
                    
                
                
            
        
浙公网安备 33010602011771号