博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何实现文件的上传
阅读量:6896 次
发布时间:2019-06-27

本文共 1110 字,大约阅读时间需要 3 分钟。

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+"复制成功!");
}
}

转载于:https://www.cnblogs.com/charlas/p/7576639.html

你可能感兴趣的文章
PV、UV、IP之间的区别与联系
查看>>
ssh 操作 esxi 基本命令
查看>>
调用HtmlTestRunner生成测试报告为空
查看>>
最优装载(贪心)
查看>>
DAY10-MYSQL数据类型
查看>>
【学时总结】◆学时·VII◆ 高维DP
查看>>
SQL Server进制
查看>>
简单的编辑器
查看>>
Android 数据库管理— — —更新数据
查看>>
cmd命令
查看>>
算法笔记 --- Counting Sort
查看>>
LeetCode 88 Merge Sorted Array
查看>>
HDU 3974 Assign the task
查看>>
Java并发之(3):锁
查看>>
11.2JS笔记
查看>>
oracle11G 命令【导库数量对比】
查看>>
快速优化yum (for centos5.5)
查看>>
Qt学习之路_8(Qt中与文件目录相关操作)
查看>>
第三章数据结构小结
查看>>
Linux FTP的安装与配置
查看>>