码迷,mamicode.com
首页 > Web开发 > 详细

如何实现文件的上传

时间:2017-09-22 19:41:34      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:put   复制   exception   name   not   load   puts   print   run   

package upload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* 将c:\\a.doc的文件复制到d:\\a.doc
*/
public class Test {
public static void main(String[] args) throws Exception {
getInputStream("c://a.doc", "d://a.doc");
}

private static void getInputStream(String pathName,String copyName) throws FileNotFoundException, IOException{
File file = new File(pathName);
if(!file.exists()){
throw new RuntimeException("文件不存在");
}else{
getCopy(copyName, new BufferedInputStream(new FileInputStream(file)));
}

}
private static void getCopy(String copyName,BufferedInputStream bis) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(copyName));
BufferedInputStream biss=bis;
byte[] b = new byte[biss.available()];
int len = 0;
while((len=biss.read(b))!=-1){
bos.write(b, 0, len);
}
bos.close();
biss.close();
System.out.println(copyName+"复制成功!");
}
}

如何实现文件的上传

标签:put   复制   exception   name   not   load   puts   print   run   

原文地址:http://www.cnblogs.com/charlas/p/7576639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!