2019-3-6 复制粘贴
输入与输出~
代码块:
1 package com.test;
2
3 import com.sun.deploy.net.FailedDownloadException;
4
5 import java.io.File;
6 import java.io.FileInputStream;
7 import java.io.FileOutputStream;
8 import java.io.IOException;
9
10 public class CopyPaste {
11 public static void main(String[] args) {
12 FileInputStream fis = null;
13 FileOutputStream fos = null;
14 try{
15 fis = new FileInputStream("bdqncopy.txt");
16 fos = new FileOutputStream("bdqn.txt");
17
18 int result = -1;
19 String info = "";
20 System.out.println("能够读取到的字节数:"+fis.available());
21 while ((result = fis.read())!=-1){
22 info +=(char)result;
23 }
24 System.out.println("读取完毕,准备复制");
25 byte[]bytes = info.getBytes();
26 fos.write(bytes,0,bytes.length);
27 System.out.println("复制完毕,请刷新工程查看文件");
28 fos.flush();
29 }catch (FailedDownloadException e){
30 e.printStackTrace();
31 }catch (IOException e){
32 e.printStackTrace();
33 }finally {
34 try{
35 if (fos!=null){
36 fos.close();
37 }
38 if (fis!=null){
39 fis.close();
40 }
41 }catch (IOException e){
42 e.printStackTrace();
43 }
44 }
45 }
46 }
输出结果:
今日更新完毕~over!