Как сказал AlexR, проверьте ваши права доступа к каталогу, в который вы пытаетесь написать.
аюсь скопировать файл в Java и переместить его в новую папку. Это код, который я использовал, но я всегда получаю эту ошибку «(Доступ запрещен) в указанном каталоге». Есть ли способ, как я могу это исправить или лучший способ скопировать файлы? Спасибо
try{
File f1 = new File(fpath);
File f2 = new File("C:/users/peter/documents/foldertest2/hats");
InputStream in = new FileInputStream(f1);
//For Append the file.
//OutputStream out = new FileOutputStream(f2,true);
//For Overwrite the file.
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
}
catch(FileNotFoundException ex){
System.out.println(ex.getMessage() + " in the specified directory.");
System.exit(0);
}
catch(IOException e){
System.out.println(e.getMessage());
}
ОБНОВЛЕНИЕ: я проверил права доступа к папке, и все они открыты для всех пользователей и мои