5

I'm following along the Basic I/O Tutorial on Oracle.com, but I'm having difficulty making a Path object:

Path p1 = Paths.get("/tmp/foo");

Which gives the error:

error: The method get(URI) in the type Paths is not applicable for the arguments (String).

I'm on Linux and I'm working in Eclipse Kepler. I'm trying to access a text file in the current directory. Using Scanner and File I can work with the file, but I'd also like to fiddle around with a path to the file so I can continue with the tutorial.

edit: The entirety of the program is below. The second half is me being a rookie and confirming the file exists/works. When I comment out the Path definitions, I get the output of "Test" which is in the 'save.txt' file.:

package projectSARA;
import java.util.*;
import java.io.*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {

    public static void main(String[] args) {

        String saveFile = "save.txt";
        Path p1 = Paths.get(saveFile);
        Path p2 = Paths.get("save.txt");

        File file = new File(saveFile);
        try{
        Scanner in = new Scanner(file);
        String test = in.next();
        System.out.println(test);
        }
        catch(FileNotFoundException e){
            System.out.println("File not found");
        }
    }// end main

}
1
  • 2
    Your code looks valid and it should not cause a compiler error. Please copy/paste a complete example into your question (including import statements) that produces this compiler error. Commented Mar 25, 2014 at 10:08

2 Answers 2

5

It appears to be a problem of the (default) JRE settings in Eclipse.

To solve it, in the Package Explorer, right-click the "JRE System Library" > properties.

Select "Execution environment", then select "JavaSE-1.7 (java-7-oracle)", press OK.

It happened to me when creating a new project outside the workspace.

Sign up to request clarification or add additional context in comments.

Comments

2

Actually I had the same issue with Oracle Java 8 running on Eclipse. But the solution above didn't help. The solution for me was to simply:

  1. right-click on project in Package Explorer
  2. Select Java Compiler
  3. Enable Project Specific Settings
  4. Set Compiler Compliance Level to 1.7

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.