How to copy a file from Linux System to Windows system using Java program? Thanks for your help. I want to copy file from linux : /inet/apps/test.java to windows System1: C:\apps\test We can use following program to copy
public static void copyFiles(String fromFile, String toFile ){
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(fromFile);
to = new FileOutputStream(toFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead); // write
}catch(Exception e){e.printStackTrace();}
finally {
if (from != null)
try { from.close();} catch (IOException e) {}
if (to != null)try {to.close();} catch (IOException e) {}
}
}
This program is running on linux.
so fromFile = /inet/apps/test
. What will be the toFile
path. If i use simply C:\apps\test
then how applicaiton recognise the target as System1
.