了解,开发中不用
若要COPY请使用BufferedInputStream/BufferedOutputStream 或 FileInputStream/FileOutputStream

实现

  1. public class Test02SystemInOutForCopy {
  2. public static void main(String[] args) throws IOException {
  3. //改变标准输入流
  4. System.setIn(new FileInputStream(".\\005IO流\\test.jpg"));
  5. //改变标准输出流
  6. System.setOut(new PrintStream(".\\005IO流\\test_system.jpg"));
  7. InputStream is = System.in;
  8. PrintStream ps = System.out;
  9. byte[] arr = new byte[1024];
  10. int len;
  11. while((len = is.read(arr)) != -1) {
  12. ps.write(arr, 0, len);
  13. }
  14. is.close();
  15. ps.close();
  16. }
  17. }