zoukankan      html  css  js  c++  java
  • java System.out、System.setIn

    //可以向文件里写数据  
    import java.io.FileNotFoundException;  
    import java.io.PrintStream;  
     
    public class TestPrintStream1 {  
        public static void main(String[] args) {  
            try {  
                PrintStream out = System.out;  
                PrintStream ps = new PrintStream("./log.txt");  
     
                System.setOut(ps);  
                int age = 11;  
                System.out.println("年龄变量成功定义,初始值为11");  
                String sex = "女";  
                System.out.println("年龄变量成功定义,初始值为女");  
                // 整合2个变量  
                String info = "这是个" + sex + "孩子,应该有" + age + "岁了";  
                System.setOut(out);  
                System.out.println("程序运行完毕,请查看日志");  
            } catch (FileNotFoundException e) {  
                e.printStackTrace();  
            }  
     
        }  

        import java.io.InputStream;  
        import java.io.FileInputStream;  
        import java.io.FileNotFoundException;  
        import java.util.Scanner;  
          
        public class TestPrintStream1 {  
            public static void main(String[] args) {  
                try {  
                    
                    InputStream in = System.in;  
                    InputStream ps = new FileInputStream("./log.txt");  
                    
                    System.setIn(ps);
                    
                    Scanner scanner = new Scanner(System.in);  
                    
                    String line = "";  
                    
                    while (scanner.hasNextLine()) {  
                        
                        line = scanner.nextLine();  
                        System.out.println(line);  
                        
                    }  
                } catch (FileNotFoundException e) {  
                    e.printStackTrace();  
                }  
          
            }  
        } 


     

    原文:

    http://blog.csdn.net/xiao472613694/article/details/7313657

  • 相关阅读:
    蓝桥杯国赛--四阶幻方清晰易懂(dfs+剪枝,stl)
    蓝桥杯---九宫重排(典型bfs)
    快速排序算法细致总结!!!
    Topsis优劣解距离分析法
    golang变量的定义
    golang
    erlang的优缺点
    mongrel代码注解
    取石块 解题报告
    军队 解题报告
  • 原文地址:https://www.cnblogs.com/smile0120/p/2589811.html
Copyright © 2011-2022 走看看