java.nio.file

Files.move and Files.copy is throwing java.nio.file.FileAlreadyExistsException

妖精的绣舞 提交于 2021-02-18 21:13:10
问题 I want to delete one file and rename another file with the old file but I am not able to move this file as java is throwing java.nio.file.FileAlreadyExistsException Following is the code snippet I am using static void swapData(String origFilePath, String tempFilePath) throws IOException{ Path tempPath = FileSystems.getDefault().getPath(tempFilePath); Path origPath = FileSystems.getDefault().getPath(origFilePath); try{ String origFileName = null; File origFileRef = new File(origFilePath); if

java.nio.file.ProviderNotFoundException: Provider not found

核能气质少年 提交于 2021-01-29 14:38:26
问题 I´ve got this exception provider not found, but don´t know how to solve it. Here is my code: @Bean public FileSystem fileSystem() { try { Path path = Paths.get("C:/Users/home/Desktop/mydir"); FileSystem ext2fs = FileSystems.newFileSystem(path, Thread.currentThread().getContextClassLoader()); return ext2fs; } catch (IOException e) { e.printStackTrace(); return null; } } Does anyone know what could be the problem and how to solve it. The idea is that i have this bean for filesystem, which i

How to avoid java.nio.file.AccessDeniedException when using java.nio.file.Files.move()?

自古美人都是妖i 提交于 2021-01-28 07:46:47
问题 My Java program (see below) sometimes crashes with a java.nio.file.AccessDeniedException in a java.nio.File.move() method execution. I could not understand why this exception is thrown and I have no bypass for now. Here is an example of the exception : java.nio.file.AccessDeniedException: C:\PROJECTS\PROJECT0\CHANGES -> C:\PROJECTS\PROJECT0\GEN70\CHANGES at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:95) at sun.nio.fs.WindowsException.rethrowAsIOException

Why are files deleted by Files.move() when an AccessDeniedException is thrown?

人盡茶涼 提交于 2021-01-27 06:35:37
问题 This is just meant as a conceptional question. I am using Files.move() with the StandardCopyOption.ATOMIC_MOVE option. I thought that would be safer, but turned out the files are still deleted when an AccessDeniedException is thrown. Any work around or explanation is appreciated. Code is very simple: Files.move(netDirJobs.toPath(), archiveJobs.toPath(),StandardCopyOption.ATOMIC_MOVE); OS: win7 Professional SP1 @MarkJeronimus : netDirLog.toPath().getFileSystem().provider() = sun.nio.fs

Why are files deleted by Files.move() when an AccessDeniedException is thrown?

不问归期 提交于 2021-01-27 06:34:27
问题 This is just meant as a conceptional question. I am using Files.move() with the StandardCopyOption.ATOMIC_MOVE option. I thought that would be safer, but turned out the files are still deleted when an AccessDeniedException is thrown. Any work around or explanation is appreciated. Code is very simple: Files.move(netDirJobs.toPath(), archiveJobs.toPath(),StandardCopyOption.ATOMIC_MOVE); OS: win7 Professional SP1 @MarkJeronimus : netDirLog.toPath().getFileSystem().provider() = sun.nio.fs

java - The process cannot access the file because it is being used by another process

一世执手 提交于 2020-12-01 09:46:11
问题 I have a piece of code that monitors a directory for addition of files. Whenever a new file is added to the directory, the contents of the file are picked and published on kafka and then the file is deleted. This works when I make a single request but as soon as I subject my code to 5 or 10 user request from jMeter, the contents are published on kafka successfully but the code isn't able to delete the file. I get a FileSystemException with a message that The process cannot access the file

Remove first element of a Stream in Java 8

こ雲淡風輕ζ 提交于 2020-04-10 06:49:19
问题 I have generated a Stream in Java 8 with Files.walk() method from java.nio library. The problem is that the method includes by default the root path but I do not want this element. I have solved in this case with this code using filter() method: public void listFiles(String directoryPath) { try { Path root = Paths.get(directoryPath); Files.walk(root,1) .filter(x -> !x.equals(root)) .forEach(System.out::println); } catch (IOException ex) { System.err.println("Error reading file: " +

Remove first element of a Stream in Java 8

无人久伴 提交于 2020-04-10 06:49:06
问题 I have generated a Stream in Java 8 with Files.walk() method from java.nio library. The problem is that the method includes by default the root path but I do not want this element. I have solved in this case with this code using filter() method: public void listFiles(String directoryPath) { try { Path root = Paths.get(directoryPath); Files.walk(root,1) .filter(x -> !x.equals(root)) .forEach(System.out::println); } catch (IOException ex) { System.err.println("Error reading file: " +

Java Zip File System Provider: ReadOnly on remote drive [Windows]

萝らか妹 提交于 2019-12-24 17:09:27
问题 I have a problem with Zip File System Provider: If the zip file is on a remote drive (mapped or not seems to be irrelevant), the virtual file system is readonly, although the file itself is not. I wrote a minimal sample code: public static void main(String[] args) throws IOException { File workingDir = new File(args[0]); File source = new File(workingDir, "in.zip"); File target = new File(workingDir, "out.zip"); Files.copy(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING)

Issue with Jenkins pipeline and java.nio.file.* methods

泪湿孤枕 提交于 2019-12-22 05:47:31
问题 I am trying to use methods from java.nio.file.* to perform some basic file operations in a Jenkins pipeline. Regardless of the node block in which the code exists, the code executes on the master node. In the pipeline, I have verified that the various node blocks are correct--they uniquely identify specific nodes. However, pathExists (and other code that moves, copies, or deletes files) always executes on the master node. Any ideas what's happening or how to fix it? import java.nio.file.*