欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java-IO:复制文件

程序员文章站 2022-07-02 17:29:09
io文件复制 ......
 1 import java.io.fileinputstream;
 2 import java.io.filenotfoundexception;
 3 import java.io.fileoutputstream;
 4 import java.io.ioexception;
 5 
 6 public class copyfiledemo {
 7     public static void main(string[] args) {
 8 
 9         fileinputstream fis = null;
10         fileoutputstream fos = null;
11         try {
12             fis = new fileinputstream("js.mp3");
13             fos = new fileoutputstream("copy_js.mp3");
14             // bufferedinputstream bis=new bufferedinputstream(fis);
15             // bufferedoutputstream bos=new bufferedoutputstream(fos);
16             byte[] bt = new byte[1024];
17             int len = 0;
18             while ((len = fis.read(bt)) != -1) {
19                 fos.write(bt, 0, len);
20             }
21         } catch (filenotfoundexception e) {
22             e.printstacktrace();
23         } catch (ioexception e) {
24             e.printstacktrace();
25         } finally {
26             try {
27                 if (fis != null)
28                     fis.close();
29                 if (fos != null)
30                     fos.close();
31             } catch (ioexception e) {
32                 e.printstacktrace();
33             }
34         }
35     }
36 }