문제

i am learning java.nio so one of the tutorial give me that example

public class ReadFile {

public void getFileInformation() throws IOException {   
    /*try {
        //Scanner scanner = new Scanner(file);
    while (scanner.hasNextLine())
        //System.out.println(scanner.nextLine());
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    }*/

    String file;
    file = "InputFile.txt";
    Charset charset = Charset.defaultCharset();
    Path path = Paths.get(file);
    List<String> lines = Files.readAllLines(path, charset);
}
}

he did not write any path he just assign it to String type with name of the file the path i know is like this c://file//file//file why is that and how to assign it to right path tutorial slide for this example slides

도움이 되었습니까?

해결책

A relative file path such as InputFile.txt is a path to a file named InputFile.txt, and located in the current directory. The current directory is the directory from which the java command is executed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top