import java.io.BufferedReader;
import java.io.FileReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("d:/1.txt"));
String line = null;
LinkedList
while ((line = reader.readLine()) != null) {
list.add(line);
}
for (int i = list.size() - 1; i >= 0; i--) {
System.out.println(list.get(i));
}
reader.close();
}
}
Scanner scanner;
try{
scanner=new Scanner(new File("filename"));
}catch(FileNotFoundException e){
e.printStackTrace();
System.out.println("Error openning the file"+filename);
}
LinkedListlinkedList = new LinkedList ();
while(scanner.hasNextLine()){
linkedList.addLast(scanner.nextLine());
}
scanner.close();
for(String s : linkedList){
System.out.println(s);
}
Listcontents = new ArrayList<>(Files.readAllLines(Paths.get(parent, filename)));
Collections.reverse(contents);
for(String line : contents)
System.out.println(line);
需要jdk7