- import java.io.*;
- class Test15
- {
- public static void main(String args[]) throws IOException
- {
- File src = new File("D:\\abc");
- File des = new File("E:\\");
- copy(src,des);
- }
- public static void copy(File src,File des) throws IOException
- {
- File desto = new File(des,src.getName());
- desto.mkdir();
- File[] files = src.listFiles();
- for(File f:files)
- {
- if(f.isDirectory())
- copy(f,desto);
- else
- {
- FileInputStream fis = new FileInputStream(f);
- File newfile = new File(desto,f.getName());
- FileOutputStream fos = new FileOutputStream(newfile);
- byte[] buf = new byte[1024];
- int len;
- System.out.println(fis.read());
- while((len=fis.read(buf))!=-1)
- {
- fos.write(buf,0,len);
- }
- fis.close();
- fos.close();
- }
- }
- }
- }
复制代码 代码如图。
为何输入流读取到的是-1
|