|
@@ -308,13 +308,25 @@ public class SftpClientUtil {
|
|
*
|
|
*
|
|
* @param directory SFTP服务器的文件路径
|
|
* @param directory SFTP服务器的文件路径
|
|
* @param downloadFile SFTP服务器上的文件名
|
|
* @param downloadFile SFTP服务器上的文件名
|
|
- * @return 字节数组
|
|
|
|
|
|
+ * @param downLoadFilePath 保存路径
|
|
|
|
+ * @param finalFileName 准备生成的文件名
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
*/
|
|
*/
|
|
public byte[] downloadRuralProject(String directory, String downloadFile,String downLoadFilePath,String finalFileName) throws IOException {
|
|
public byte[] downloadRuralProject(String directory, String downloadFile,String downLoadFilePath,String finalFileName) throws IOException {
|
|
File dirFile = new File(downLoadFilePath);
|
|
File dirFile = new File(downLoadFilePath);
|
|
if (!dirFile.exists()) {
|
|
if (!dirFile.exists()) {
|
|
dirFile.mkdirs();
|
|
dirFile.mkdirs();
|
|
}
|
|
}
|
|
|
|
+ //睡眠1毫秒 用来防止相同文件名被替换
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ //文件名处理(将文件名拆分为名称和后缀名为之后添加时间戳做准备)
|
|
|
|
+ String headName = finalFileName.substring(0,finalFileName.lastIndexOf("."));
|
|
|
|
+ String endName = finalFileName.substring(finalFileName.lastIndexOf("."),finalFileName.length());
|
|
if("1".equals(uploadMode)){
|
|
if("1".equals(uploadMode)){
|
|
OutputStream out = null;
|
|
OutputStream out = null;
|
|
InputStream in = null;
|
|
InputStream in = null;
|
|
@@ -333,7 +345,7 @@ public class SftpClientUtil {
|
|
downLoadFilePath += "/";
|
|
downLoadFilePath += "/";
|
|
}
|
|
}
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
- fileOut = new FileOutputStream(downLoadFilePath + downloadFile);
|
|
|
|
|
|
+ fileOut = new FileOutputStream(downLoadFilePath + headName + System.currentTimeMillis() + endName);
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
byte[] buf = new byte[4096];
|
|
byte[] buf = new byte[4096];
|
|
int length = bis.read(buf);
|
|
int length = bis.read(buf);
|
|
@@ -364,7 +376,7 @@ public class SftpClientUtil {
|
|
//将文件读入文件流
|
|
//将文件读入文件流
|
|
InputStream inStream = new FileInputStream(fileurl);
|
|
InputStream inStream = new FileInputStream(fileurl);
|
|
|
|
|
|
- File file = new File(downLoadFilePath,finalFileName);
|
|
|
|
|
|
+ File file = new File(downLoadFilePath,headName + System.currentTimeMillis() + endName);
|
|
//将下载保存到文件。
|
|
//将下载保存到文件。
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
Streams.copy(inStream, out, true);
|
|
Streams.copy(inStream, out, true);
|
|
@@ -377,7 +389,7 @@ public class SftpClientUtil {
|
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
|
|
- FileOutputStream fileOut = new FileOutputStream(downLoadFilePath + "/" + finalFileName);
|
|
|
|
|
|
+ FileOutputStream fileOut = new FileOutputStream(downLoadFilePath + "/" + headName + System.currentTimeMillis() + endName);
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
|
|
|
|
|
|
byte[] buf = new byte[4096];
|
|
byte[] buf = new byte[4096];
|