标签:读取 spl linked klist class cep none date nbsp
import java.io.*; import java.util.LinkedList; import static util.Print.print; public class LoadTest { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("src/LoadTest.java")); String str; LinkedList<String> ls=new LinkedList<String>(); while ((str = in.readLine()) != null) { ls.addFirst(str+"\n"); } in.close(); print(ls); } }
输出:
[ , } , } , print(ls.toString()); , in.close(); , } , ls.addFirst(str+"\n"); , while ((str = in.readLine()) != null) { , LinkedList<String> ls=new LinkedList<String>(); , String str; , BufferedReader in = new BufferedReader(new FileReader("src/LoadTest.java")); , public static void main(String[] args) throws IOException { , public class LoadTest { , , import static util.Print.print; , , import java.util.LinkedList; , import java.util.Date; , import java.io.*; ]
使读取的文件的名字作为命令行参数形式提供.
public class LoadTest { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader(args[0])); String str; LinkedList<String> ls=new LinkedList<String>(); while ((str = in.readLine()) != null) { ls.addFirst(str+"\n"); } in.close(); print(ls); } }
所有行变成大写形式
public class LoadTest { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader(args[0]); String str; LinkedList<String> ls=new LinkedList<String>(); while ((str = in.readLine()) != null) { ls.addFirst((str+"\n").toUpperCase()); } in.close(); print(ls); } }
打开一个文本文件,每次读取一行内容,将每一行作为String读入,并将Sring对象置入LinkedList中,按相反顺序打印出LinkList所有行.
标签:读取 spl linked klist class cep none date nbsp
原文地址:https://www.cnblogs.com/lIllIll/p/11361253.html