1

I have some file containing lots of numbers (test input), so I want to print it somehow to console.

But If I go to run configuration and I set InputFile: to input.txt then console returns:

[Invalid file specified for stdin file: input.txt]

Anyone know what's the problem?

Aleksandar Makragić
  • 1,957
  • 17
  • 32
  • Where is the `input.txt` located on your hard drive? And which working directory does your launch config use? – slartidan Jun 20 '15 at 08:30
  • http://www.dodaj.rs/f/n/vk/2EEvHe1N/untitled.png here is photo, I'm not sure what do you mean by "which working directory does your launch config use?" – Aleksandar Makragić Jun 20 '15 at 09:54

1 Answers1

0

I'm not sure, about how you want to access your input file. As far as I know, there is no eclipse feature, that allows using files as System.in. (see Eclipse reading stdin (System.in) from a file )

I tried to reproduce your eclipse setup (as posted in your comment) and built a simple program, that outputs every line of the input.

Java8:

public class Main {

    public static void main(String[] args) throws IOException, URISyntaxException {

        // get resource from classpath
        URL resource = ClassLoader.getSystemResource("quickfind/largeUF.txt");
        Path path = Paths.get(resource.toURI());

        // read all lines
        List<String> allLines = Files.readAllLines(path);

        // print all lines
        allLines.stream().forEach(System.out::println);
    }
}

Java7:

public class Main {

    public static void main(String[] args) throws IOException, URISyntaxException {

        // get resource from classpath
        URL resource = ClassLoader.getSystemResource("quickfind/largeUF.txt");
        Path path = Paths.get(resource.toURI());

        // read all lines
        List<String> allLines = Files.readAllLines(path);

        // print all lines
        for (String line : allLines) {
            System.out.println(line);
        }
    }
}
Community
  • 1
  • 1
slartidan
  • 20,403
  • 15
  • 83
  • 131
  • I want to do next: Rather then to enter manually 1 000 000 numbers into console, those numbers are all stored in file. So I want just to copy somehow that info to console. Simple copy-paste works, but that is not how I want it done. I'm using these two libraries: http://introcs.cs.princeton.edu/java/stdlib/StdIn.java.html and http://introcs.cs.princeton.edu/java/stdlib/StdOut.java.html – Aleksandar Makragić Jun 21 '15 at 10:50