Michael... hat gesagt.:new File(pfadName).createNewFile()
new File(System.getProperty("user.dir") + "/hallo/").createNewFile();
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class DateiKopierenClass {
public static void main(String[] args) throws IOException {
// Pfade entsprechend anpassen
File inF = new File("/home/user/inputFile.txt");
File outF = new File("/home/user/outputFile.txt");
copyFile(inF, outF);
}
public static void copyFile(File in, File out) throws IOException {
FileChannel inChannel = new FileInputStream(in).getChannel();
FileChannel outChannel = new FileOutputStream(out).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} catch (IOException e) {
throw e;
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
}
Exception in thread "main" java.io.FileNotFoundException: C:\PfadWoEsHingehört\java (Zugriff verweigert)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at copyfile.DateiKopierenClass.copyFile(DateiKopierenClass.java:20)
at copyfile.DateiKopierenClass.main(DateiKopierenClass.java:15)
Java Result: 1