Reading an Existing File
Reading a file can be done in a simple way. The question is about where you will store the data once you have it. We will work with lists, iterate through the lists, and then print out the results to System.out
. The next example uses readAllLines()
to open the existing file and reads the contents into the computer's memory, putting them into the fileContent
list. After that, we use an iterator to go through each line and send them to the Terminal:
import java.io.IOException; import java.nio.file.*; import java.util.List; public class Example08 { Â Â Â Â public static void main(String[] args) { Â Â Â Â Â Â Â Â String pathString = System.getProperty("user.home") + "/javaTemp/temp.txt"; Â Â Â Â Â Â Â Â Path pathFile = Paths.get(pathString); Â Â Â Â Â Â Â Â try { Â Â Â Â Â Â Â Â Â Â ...