159
questions
1
vote
1
answer
49
views
java.nio.file.Files.walk() sorting guarantee?
The java nio Files API gives several options to list the contents of a directory:
list
walk
walk
I am looking for a way to be able to recursively enumerate contents of a directory sorted by name.
...
0
votes
1
answer
43
views
PNG file corrupted after calling ImageReader getHeigth
I got my png file corrupted after calling :
BufferedImage im = ImageIO.read(inputStream);
You will find the service life cycle below :
InputStream inputStream = multipartFile.getInputStream();
...
1
vote
0
answers
356
views
Static method exists( sun.nio.fs.WindowsPath, java.nio.file.LinkOption ) not found in class'java.nio.file.Files'
I am working in Java 11.0.11 with Amazon Corretto.
This code is running in a beanshell file as part of an identity governance system.
I am trying to use java.nio methods with Windows network paths.
I ...
-1
votes
1
answer
206
views
Attempting to create objects in loop while reading files and getting error
I'm creating a program for school that reads a text file, stores the data into variables, and then creates an object to pass the data into for later use. I'm using a scanner class for file reading at ...
0
votes
0
answers
392
views
AccessDeniedException when trying to zip folder
I want to zip a directory and it is content and download with REST request, but i get java.nio.file.AccessDeniedException error when i copy the directory.
public void downloadZipFile(String folderName,...
1
vote
0
answers
628
views
java Files.copy copy readonly attribute without COPY_ATTRIBUTE option
i try to copy files without their filesystem attributes. there are some readonly only files, but i do not want their copy to be readonly. so i use
Files.copy(src,target,REPLACE_EXISTING);
but... the ...
-1
votes
1
answer
163
views
Java loses the last "/" character of the path
I am developing a java application to perform operations with files.
In particular, I perform move and copy of files .. and I have programmed two functions.
Functions take strings such as sourcePath ...
1
vote
2
answers
1k
views
Java can't access file on local path
Asked this question, having already tried possible solutions in other questions here on stack but that didn't allow me to fix the problem.
As in the title, I have created a java utility with which I ...
1
vote
2
answers
3k
views
Java filter file by name and extension
I'm developing a little Java program for my company.
In this program I need to retrieve from my local folder some files, but i need to search the files by the first three character and by extension.
...
0
votes
0
answers
1k
views
JAVA: java.nio.Files move command not working for shared NAS location
I'm trying to move a file from a local directory to a shared NAS directory. But I'm getting "java.nio.file.AtomicMoveNotSupportedException" exception. Can anyone let me know whether there is ...
0
votes
2
answers
2k
views
SpringBoot absolute path clarification
I'm new to SpringBoot web dev.
I need to save an image to a directory in the current project. I have given path as "String uploaddir = "./src/main/imageuploads/"+ savedadvert.getId();&...
2
votes
1
answer
2k
views
Java 16 Modularisation IllegalAccessException Java.NIO Spring Boot
I'm new to Java and have been coding in JDK 11, but now using JDK 16. When I try to open a database connection method from the Spring Boot main class, by calling the database connection class, even ...
0
votes
1
answer
89
views
Source Directory is deleted whenever File is moved from Target Directory [Kotlin]
When ever I run the program the files will successfully move to the intended target directory.
However while doing so the source directory is deleted, The purpose of the code is to move txt files to ...
0
votes
1
answer
190
views
ulimit issue with spring boot and Files.nio
We are using spring batch and integration in one of our project
We used spring integration for polling and monitoring a directory; when a file comes into the directory, we log and move to a different ...
0
votes
1
answer
303
views
LazySodiumJava FileSystemNotFoundException Occured
I'm trying to use LazySodiumjava library, but I got an errors follow:
java.nio.file.FileSystemNotFoundException
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(...
1
vote
1
answer
200
views
Deadlock occurring when using java.nio.file.Paths & jsfml loadFromFile
I've been trying to debug a problem I've had with loading a font from file (a .ttf file) with the java.nio.file.Paths import, using a combination of Paths.get() and loadFromFile(), but can't seem to ...
-2
votes
1
answer
331
views
why use the Package java.nio.file.Path without importing it? [closed]
i have the two classes :
public class ScriptTests {
private final java.nio.file.Path test_file;
// ...
}
public class TestD {
public static void main(String args[]) {
java.nio.file.Path ...
1
vote
1
answer
617
views
Why BufferedWriter is not writing into the file over the opened FileChannel?
Below is my code. I am able to successfully read the file. But not able to re-write onto it with the replaced content using BufferedWriter. But can do it with ByteBuffer. Any suggestions please where ...
0
votes
0
answers
160
views
How to use DirectoryStream in java 6?
I have below code which is working correctly in Java 7. But how can I make it work for Java 6??
List<Map<String, String>> map = new ArrayList<Map<String, String>>();
...
1
vote
1
answer
2k
views
converting java.nio.file.Path to File got failed
I am trying to get .cer files packed inside a jar and install them dynamically to keystore using java .
private List<File> doSomething(Path p) {
List<java.io.File>FileList=...
0
votes
1
answer
753
views
Check does file exist java.nio
I'm trying to check does file exist but it doesn't work.
FileSystem fs = FileSystems.getDefault();
Path p = fs.getPath(fileName);
if(!Files.exists(p)) {
create(fileName);
} else {
throw new ...
1
vote
1
answer
6k
views
java.nio.file.ProviderNotFoundException: Provider not found
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/...
5
votes
5
answers
2k
views
How to copy multiple files atomically from src to dest in java?
in one requirement, i need to copy multiple files from one location to another network location.
let assume that i have the following files present in the /src location.
a.pdf, b.pdf, a.doc, b.doc, a....
-1
votes
3
answers
4k
views
Unable to create directory in LINUX (java.nio.file.AccessDeniedException)
I'm trying to make a job to automate the process of creating a folder.
I can make the job work on windows but not on Linux and the exception makes no doubt about the problem, but the directory in ...
1
vote
1
answer
517
views
Can you use 2 java nio file systems in one program?
I am writing a project that will generate a folder structure from a template folder structure (which I package inside my jar as a resource). I want to keep all the resources inside my program's jar ...
0
votes
1
answer
126
views
How can I open a FileInputStream that has its share set to allow ReadWrite?
In .Net I can open a FileStream set to FileAccess.Read, FileShare.ReadWrite. How can I do the same in Java?
Files.newInoutStream() does not appear to support either of these capabilities.
Update: Let ...
0
votes
1
answer
2k
views
Getting an element inside a directory using java.nio.file.Path's
I am currently getting to grips with file management in Java. As far as i've read, java.nio.file.Path is the preferred way of doing so.
Say I want to copy the contents of oldDir to the, currently ...
0
votes
1
answer
564
views
Files.delete does not delete empty directory
I am trying to delete file from file system, and check whether are directory and its parent directories containing it are empty to delete them also:
Path filePath = Paths.get(document.getUrl());
...
0
votes
0
answers
250
views
Get directory name from Path object without a slash at the end
When I have a Path object (in my case, it's relativized path coming from Files.walkFileTree), path.getFileName().toString() may give me a name with a slash at the end. Is there some simple builtin ...
0
votes
1
answer
2k
views
Replacement or way of using ShellFolder.getShellFolder() on Java 11
I'm currently using ShellFolder.getShellFolder() to determine if a particular path is on a local drive (directly connected to Windows machine) or a remote drive.
package com.jthink.songkong.analyse....
1
vote
1
answer
677
views
Java Files.walkTree() sub directory problem
My platform is Centos 7.0, I'm working in Java 8.
My question is how java.nio.file,Files.walkFileTree() should be used to look for files in a directory tree that contains some files and directories ...
1
vote
3
answers
525
views
How to check folder size or containing files in Java without knowing the file name with java.nio.file?
I had a similar question some time ago. Now I don't have any specific file name, because it is a preprocessor script. So I need to check the file size of a list of files or the size of a specific path....
4
votes
1
answer
2k
views
How does Jackson automatically deserialize java.nio.file.Path?
I'm not complaining, but would like to understand why it works.
This is my Java class:
public static class ExampleClass {
private Path target;
public Path getTarget() {
return target;
}
...
0
votes
0
answers
780
views
AWS SDK says "Profile file does not exist" even if the credential file exist
AWS Java SDK throws the error "Profile file '$credential_path' does not exist" if the credential_path includes any hidden folder like "c:\\\\User\\\\.aws\\\\credentials".
How to make it work?
AWS ...
0
votes
0
answers
106
views
Unable to read Windows file even when it has "Read" permission set through java
I am trying to set permissions for a file to the Administrators group from java in windows.
Below is my code:
public static void main(String[] args) throws IOException {
final Path path = Paths....
1
vote
3
answers
27k
views
How to avoid java.nio.file.AccessDeniedException when using java.nio.file.Files.move()?
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 ...
0
votes
0
answers
437
views
How to copy folder from src/main/resources to a dynamic location in Java?
I've a folder with name "test" and has many folders and files inside it. I've to copy this folder to a dynamic location in Java. Below is the code I've written:
class FileManager {
public static ...
1
vote
2
answers
2k
views
scala delete all files but not directory
I have a directory and subfolder in it.
The directory contains 5 file and one subdirectory.
I need to empty the subfolder and delete 3 files out of 5.
Currently I am using below code which is ...
0
votes
0
answers
346
views
FileAlreadyExistsException for a deleted directory
For the purpose of making a backup, I copy a directory with tests scripts to another location. For this I'm using Files.walkFileTree(fromDir, SimpleFileVisitor).
This works as expected and I can ...
13
votes
2
answers
3k
views
How to handle FileSystemAlreadyExistsException?
How should you handle a FileSystemAlreadyExistsException when calling FileSystems.newFileSystem?
One way would be to use the already created FileSystem (getFileSystem), but then you could run into ...
0
votes
0
answers
146
views
Replace specific file in a zip file using java
I would like to replace a specific file (README.MD) in prj-basics-final.zip with the external file of the same name.
The code below doesn't replace README.MD in prj-basics-final.zip. It doesn't throw ...
0
votes
2
answers
35
views
Java Paths: Build and absolute path
Currently, I'm getting an absolute path using "/" + approach, I don't feel confortable with.
Paths.get("/" + someFolder, this.backOfficeProperties.getMassivePendingLocation());
I guess there has to ...
3
votes
0
answers
1k
views
java.nio.file Files.isWritable not working with network shared drives
I have a java application that write files on given location.
Before writing I am checking if provided path is writable by using Files.isWritable(path).
When user is giving the path of folder that ...
0
votes
1
answer
145
views
How to read a file from a path containing two or more zipfiles in between?
Assume I have a path:
/path/to/zipfile.zip/my/earfile.ear/plainfile
where zipfile.zip is a zip file, and earfile.ear is a ear file. The presence of those compressed files are arbitrary.
I want to ...
0
votes
1
answer
596
views
java : What is the exact functionality of buffer.flip() method?
try (FileOutputStream binFile = new FileOutputStream("data.dat");
FileChannel binChannel = binFile.getChannel()) {
ByteBuffer buffer = ByteBuffer.allocate(100);
byte[] ...
1
vote
3
answers
1k
views
Java read the file name and stored in ascending order
Reading the files from a particular directory and stored all the file names in the arraylist
File directory = new File(path);
File[] listOfFiles = directory.listFiles();
int fileCount ...
4
votes
1
answer
4k
views
How to create a FileSystem object for a *directory* using an absolute path?
I'm creating a command line application that needs to output some files (more than one) into either a ZIP file or a plain folder depending on the paramters given.
My approach is to encapsulate the ...
0
votes
1
answer
5k
views
How to use FileSystem.getPath() as target for a (File-)Writer?
I have an app that outputs some files.
Depending on a configuration I Need to put them either in a plain Folder or in a zip file.
I'm trying to use FileSystem to decoople the Code actually writing ...
0
votes
1
answer
2k
views
Exception throw when creating Path instance
I am trying to create an instance of Path's class at a specific folder by using environment variable. Here is my code:
Path pathName = Paths.get(System.getenv("USER") + "/AGENDA");
System.out.println(...
0
votes
0
answers
38
views
Java translate reflection-invoked program's file API paths
I am trying to implement something like virtual machine in Java. Yes, it NEEDS
to be made in java, since it wraps some already-coded java library and implements
it's abstractions. But on the problem......