我有這段代碼可以將文件從IFS複製到本地驅動器。我想問一些關於如何改善它的建議。在代碼中使用JT400的IFS文件副本
public void CopyFile(AS400 system, String source, String destination){
File destFile = new File(destination);
IFSFile sourceFile = new IFSFile(system, source);
if (!destFile.exists()){
try {
destFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
IFSFileInputStream in = null;
OutputStream out = null;
try {
in = new IFSFileInputStream(sourceFile);
out = new FileOutputStream(destFile);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (AS400SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(in != null) {
in.close();
}
if(out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} // end try catch finally
} // end method
凡
- 源=全IFS路徑+文件名和
- 目的地=完整本地路徑+文件名
我想問一下關於以下一些事情:
a。性能考慮因素
- 這會對主機AS400系統的CPU使用率產生很大影響嗎?
- 這會對使用的JVM產生很大的影響(根據內存使用情況)
- 會將這種情況包含到Web應用程序中,從而影響應用程序服務器性能(這是否是一項沉重的任務)?
- 將使用此複製多個文件(冗餘運行)是所有涉及的資源的一大負擔?
b。代碼質量
- 我的IFSFileInputStream實現是否足夠了,還是一個簡單的FileInputStream對象能很好地完成這項工作?
據我所知,我只是需要AS400對象,以確保所引用的源文件是從IFS文件。
我是AS400和IFS的noob,想問一個有經驗的人的誠實意見。
謝謝你這麼多的快速回答托爾比約恩。我也想到了as400.disconnectAllServices()部分,這將是我的類的清理方法(銷燬)的一部分。是的,我希望我很快能找到一種更好地處理try-catch塊的方法。我還計劃使用log4j而不是使用printStackTrace來記錄異常。但是,如何處理異常並很好地通知調用代碼?再次感謝。 – aEtherv0id