سؤال

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