Hello. Such a task: you need to read numbers from a file, make certain manipulations with them, then output them to the console. Which classes are best for I / O?
- In what format are the numbers? Give an example of several lines of a file. - dlarchikov
- 6 44 55 103 1664 or each in a new line - slavqache
|
1 answer
First you need to create a file object.
File f = new File("/path/to/file"); Then we go along the path of least resistance, so we use befferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f))); String line; while ((line = br.readLine()) != null) { System.out.println(line); } |