File transfer & File rename & Folder creation in java codes
来源:互联网 发布:包包淘宝店名起名大全 编辑:程序博客网 时间:2024/05/17 08:12
public static void tranferFile(String fromPath, String toPath,String file) {
InputStream inStream = null;
OutputStream outStream = null;
String name = "";
if(file.indexOf(".")!=-1)
name = file.substring(0,file.indexOf("."));
File path = new File(toPath);
if (!path.exists()){
path.mkdirs();
}
try {
File afile = new File(fromPath + file);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHMM");
String destFile = name+"."+formatter.format(new java.util.Date());
File bfile = new File(toPath + destFile);
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
if (afile.exists())
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
String finalFile = name+".zip";
boolean success = bfile.renameTo(new File(toPath + finalFile) );
} catch (IOException e) {
e.printStackTrace();
}
}
InputStream inStream = null;
OutputStream outStream = null;
String name = "";
if(file.indexOf(".")!=-1)
name = file.substring(0,file.indexOf("."));
File path = new File(toPath);
if (!path.exists()){
path.mkdirs();
}
try {
File afile = new File(fromPath + file);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHMM");
String destFile = name+"."+formatter.format(new java.util.Date());
File bfile = new File(toPath + destFile);
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
if (afile.exists())
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
String finalFile = name+".zip";
boolean success = bfile.renameTo(new File(toPath + finalFile) );
} catch (IOException e) {
e.printStackTrace();
}
}
- File transfer & File rename & Folder creation in java codes
- File rename
- Delphi rename all file in a directory
- File Transfer
- File Transfer
- File Transfer
- File Transfer
- File Transfer
- Cannot delete file or folder in windows
- iOS: resource file folder in xCode 4
- File System Driver Creation
- AutomationException: 0x8004033a - File creation error. in 'esri.Output'
- File/Folder Chooser 选择
- File , Folder 与 Directory
- Folder & File House Keeping
- Visual studio 2010 - Invalid icon file located in 'application folder'
- File Operations In Java
- File in Java
- ubuntu 10.04 eclipse cdt 代码悬停窗口 背景颜色调整
- linux之I2C解析-------OK6410(四)
- 处理待分析日志中特征为中英文混现的方法
- Leo谈应届大学生求职1
- 各C/C++编译器对wchar_t字符和字符串的正确支持程度
- File transfer & File rename & Folder creation in java codes
- 黑马程序员---枚举学习
- 如何区分WS_POPUP、WS_OVERLAPPED和WS_CHILD
- Linux驱动子系统之I2C用户空间调用
- Leo谈应届大学生求职2
- 学习了
- 类的私有继承
- 常用MSDS查询网站
- git使用详细介绍