0

The information that I can find on string paths is confusing. Can anyone help please?

I want to read this path:

try (Scanner s = new Scanner(new File("c:/Users/Green/documents/dictionary.txt")).useDelimiter("\\s*-\\s*")) {

but via a string path and put the return line by line into an ArrayList.

Any pointers would be gratefully received.

1 Answers1

0

Try this :

        Path p1 = Paths.get("C:/Users/Green/documents/dictionary.txt");
        Scanner sc = new Scanner(p1.toFile()).useDelimiter("\\s*-\\s*");
        List<String> myList = new ArrayList<String>();
        while (sc.hasNext()) {
            myList.add(sc.next());
        }

Let me know if this is what you wanted to achieve.

  • 1
    this is a fantastic help......but what value does the path bring,,,,what benefit does it bring? –  Feb 09 '20 at 13:47