我從不同的Windows服務器獲取directoreis和文件的總字節數,但不確定是否需要在這兩種方法中使用try catch塊?請幫助它需要一個try catch塊
private void retrieveTotalBytes(File sourceFile)
{
File[] files = sourceFile.listFiles();
for(File file : files)
{
if(file.isDirectory())
retrieveTotalBytes(file);
else totalBytes += file.length();
}
}
private void copyFiles(File sourceFile, File targetFile) throws IOException
{
if(sourceFile.isDirectory())
{
if(!targetFile.exists()) targetFile.mkdirs();
String[] filePaths = sourceFile.list();
for(String filePath : filePaths)
{
File srcFile = new File(sourceFile, filePath);
File destFile = new File(targetFile, filePath);
copyFiles(srcFile, destFile);
}
}
else
{ }
}
我看不到任何理由關閉此問題 –
@PreetSangha,同意。這是一個合理的問題......在這個問題上你是個不錯的人 –
你的意思是「需要」是什麼意思?爲了代碼編譯?或爲了漂亮? – yankee