概述
文件下载到本地 保存为流 然后通过流进行上传
/**
* 文件保存在本地返回一个数据流
* @param path
* @return
*/
public DataInputStream downFile(String path) {
/*String pathJmx= "C:\home\tools\";*/
try {
//从服务器下载path
File files = new File(path);
// 取得文件名。
String fileName = files.getName();
//保存位置
DataInputStream in = new DataInputStream(new FileInputStream(path));
DataOutputStream out = new DataOutputStream(new FileOutputStream(pathJmx + fileName));
BufferedReader d = new BufferedReader(new InputStreamReader(in));
String count;
while ((count = d.readLine()) != null) {
String u = count.toUpperCase();
out.writeBytes(u+ ",");
}
FileInputStream fis = new FileInputStream(pathJmx + fileName);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
/*d.close();
out.close();*/
return dis;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 把流转换为文件
* @param path
* @param is
* @return
* @throws IOException
*/
public String inputStreamToFile(String path,DataInputStream is) throws IOException {
File file = new File(path);
String name = file.getName();
String paths = "F:\Program Files\Tencent\" + name;
DataOutputStream outputStream = null;
outputStream = new DataOutputStream(new FileOutputStream(paths));
BufferedReader d = new BufferedReader(new InputStreamReader(is));
String count;
while ((count = d.readLine()) != null) {
String u = count.toUpperCase();
outputStream.writeBytes(u+ ",");
}
is.close();
outputStream.close();
return paths;
}
public static void main(String[] args) throws IOException {
String path = "C:\assert.c";
//新文件
String pathJmx = "F:\Program Files\shx.c";
DataInputStream dataInputStream = downFile(path);
//生成新的文件
String pas = inputStreamToFile(pathJmx, dataInputStream);
System.out.println("路径:" + pas);
}
最后
以上就是曾经冰淇淋为你收集整理的文件流处理的全部内容,希望文章能够帮你解决文件流处理所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复