1

I am using an array of files.

String[] allFiles = new String[]{"real.xml", "fake.xml"}; 

I am getting this error that

java.nio.file.NoSuchFileException: C:\Users\rio\rio-workspace\real.xml

I am trying to run command to know where it is looking for the file. I came across this solution but it doesn't work with array.

System.out.println(allFiles.toAbsolutePath());

Would appreciate if someone give right command to know about this problem.

Thanks

2
  • Please share the sample code you did and also add more clarity in your question Commented Feb 26, 2020 at 18:50
  • All relative files are filled in from the value in System.getProperty("user.dir"); Commented Feb 26, 2020 at 18:51

3 Answers 3

1

Do it as follows:

import java.nio.file.Paths;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        String[] allFiles = { "output.txt", "test.txt" };

        // First method
        for (String file : allFiles) {
            System.out.println(Paths.get(file).toAbsolutePath());
        }

        // Second method (by using Stream)
        Arrays.stream(allFiles).forEach(file -> System.out.println(Paths.get(file).toAbsolutePath()));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

All relative files are filled in from the value in System.getProperty("user.dir");

Comments

0

An example

File[] thoseFiles = new File(System.getProperty("user.dir")).listFiles();
for (int i = 0; i < thoseFiles.length; i++) {
    System.out.println(thoseFiles[i].getAbsolutePath());
}

Or if you chose to have the files in a folder

File[] thoseFiles = new File("ThatFolder").listFiles();
for (int i = 0; i < thoseFiles.length; i++) {
    System.out.println(thoseFiles[i].getAbsolutePath());
}

This can be expanded with a Filefilter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.