我想創建存在於一個ftp位置的文件的zip文件並將該zip文件複製到其他ftp位置而不在本地保存。壓縮存在於一個FTP位置並直接複製到另一個FTP位置的文件
我能夠處理該問題files.It的小尺寸很適合小尺寸的文件,1 MB等
但是如果文件大小大像100 MB,200 MB,300 MB那麼它給錯誤如,
java.io.FileNotFoundException: STOR myfile.zip : 550 The process cannot access the
file because it is being used by another process.
at sun.net.ftp.FtpClient.readReply(FtpClient.java:251)
at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:208)
at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:398)
at sun.net.ftp.FtpClient.put(FtpClient.java:609)
我的代碼是
URLConnection urlConnection=null;
ZipOutputStream zipOutputStream=null;
InputStream inputStream = null;
byte[] buf;
int ByteRead,ByteWritten=0;
***Destination where file will be zipped***
URL url = new URL("ftp://" + ftpuser+ ":" + ftppass + "@"+ ftppass + "/" +
fileNameToStore + ";type=i");
urlConnection=url.openConnection();
OutputStream outputStream = urlConnection.getOutputStream();
zipOutputStream = new ZipOutputStream(outputStream);
buf = new byte[size];
for (int i=0; i<li.size(); i++)
{
try
{
***Souce from where file will be read***
URL u= new URL((String)li.get(i)); // this li has values http://xyz.com/folder
/myPDF.pdf
URLConnection uCon = u.openConnection();
inputStream = uCon.getInputStream();
zipOutputStream.putNextEntry(new ZipEntry((String)li.get(i).substring((int)li.get(i).lastIndexOf("/")+1).trim()));
while ((ByteRead = inputStream .read(buf)) != -1)
{
zipOutputStream.write(buf, 0, ByteRead);
ByteWritten += ByteRead;
}
zipOutputStream.closeEntry();
}
catch(Exception e)
{
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream .close();
}
catch (Exception e) {
e.printStackTrace();
}
}
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (Exception e){
e.printStackTrace();
}
}
任何人都可以讓我知道我怎樣才能避免這種錯誤和處理大文件
你好@Aaron。如果您可以向我提供關於第2點和第3點的更多信息? – user1493286
隨時發佈新的問題。只要確定你明確提到你需要知道/不明白的東西。 –
@Aaron.Thanks.for point 2.最初,我創建目標zip文件名,然後迭代我的列表(我將添加到zip的文件)並將其添加到上面的目標zip中。我不明白你提出的這個重命名的東西。我可以如何實現這一點。另外我完全不理解你的觀點沒有3. – user1493286