黑马程序员技术交流社区

标题: 修改标准输入输出流拷贝图片 [打印本页]

作者: wstm198907    时间: 2016-7-8 23:13
标题: 修改标准输入输出流拷贝图片
public class Test01_修改标准输入输出流拷贝图片 { //开发中不推荐使用
        public static void main(String[] args) throws IOException {
                System.setIn(new FileInputStream("头像.jpg"));
                System.setOut(new PrintStream("头像_copy.jpg"));
               
                InputStream is = System.in;
                PrintStream ps = System.out;
               
                byte[] arr = new byte[1024];
                int len;
                while ((len = is.read(arr))!=-1){
                        ps.write(arr, 0, len);;
                }
               
                is.close();
                ps.close();
        }
}
作者: TCK8888    时间: 2016-7-8 23:21
温故而知新,写法挺新颖的啊




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2