コピー/削除操作を含む、コードベースの単純なファイル操作を行う必要があります。問題は、ファイルの場所をパスとして宣言する場合です
File remotefile = new File("//mypc/myfolder/myjar.JAR");
Windows はネットワーク内のファイルを見つけて操作を行いますが、Linux マシンはファイルを見つけることができません。
File remotefile = new File("file://mypc/myfolder/myjar.JAR");
両方のプラットフォームがファイルを見つけます。今、私はファイルをコピーする方法を持っています:
public static void copyFile(File sourceFile, File destFile) throws IOException {
if(!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally {
if(source != null) {
source.close();
}
if(destination != null) {
destination.close();
}
}
}
ファイル URI をこのメソッドに送信すると、両方のプラットフォームでファイルを見つけることができません。しかし、パスとして送信すると、Windows マシンは正常に動作しますが、Linux マシンはファイルを見つけることができません。
ここで何が問題になる可能性がありますか?