求一个java的文件读取小程序的修改
借鉴这两个程序,或在此基础上修改,得一个程序ShowAllFiles.java要求得出的运行结果是以下这样,自己完全不知道是什么意思!老师没有给文件啊!参考ShowFil...
借鉴这两个程序,或在此基础上修改,得一个程序ShowAllFiles.java要求得出的运行结果是以下这样,自己完全不知道是什么意思!老师没有给文件啊!参考ShowFile1.java
还有WriteFile1.java
1:import java.io*;
2:
3. public class WriteFile1 {
static void main(String[] args) {
5 : if (args length! = 1) {
6 System.out.println("使用方法:java WriteFile1 文件");
7 System.out.println("例:java WriteFile1 output.txt<input.txt");
8 : System .exit(O);
9 }
10 String filename= args[O];
11 try {
12: BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
13 PrintWriter writer = new PrintWriter(new PrintWriter(new BufferedReader(new FileWriter(filename)));
14 String line;
15 while((line = reader .readLine () ) != null) {
16 : writer .println(line);
17 }
18 reader close () ;
19 writer .cl ose () ;
20 } catch(IOException e){
21: System.out.print(e);
22 }
23 }
24 }
这是运行结果
% ls test Alice Bob% cat test/Alice This is Alice.% cat test/Bob This is Bob.% java ShowAllFiles testFile: test/AliceThis is Alice.File: test/BobThis is Bob.
求助!拜托了!谢谢~~! 展开
还有WriteFile1.java
1:import java.io*;
2:
3. public class WriteFile1 {
static void main(String[] args) {
5 : if (args length! = 1) {
6 System.out.println("使用方法:java WriteFile1 文件");
7 System.out.println("例:java WriteFile1 output.txt<input.txt");
8 : System .exit(O);
9 }
10 String filename= args[O];
11 try {
12: BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
13 PrintWriter writer = new PrintWriter(new PrintWriter(new BufferedReader(new FileWriter(filename)));
14 String line;
15 while((line = reader .readLine () ) != null) {
16 : writer .println(line);
17 }
18 reader close () ;
19 writer .cl ose () ;
20 } catch(IOException e){
21: System.out.print(e);
22 }
23 }
24 }
这是运行结果
% ls test Alice Bob% cat test/Alice This is Alice.% cat test/Bob This is Bob.% java ShowAllFiles testFile: test/AliceThis is Alice.File: test/BobThis is Bob.
求助!拜托了!谢谢~~! 展开
展开全部
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class zz {
public static void main(String[] args) throws Exception {
File[] file=new File(args[0]).listFiles();
for (File s:file){
BufferedReader reader=new BufferedReader(new FileReader(s));
System.out.println("File: "+s.getPath());
String line;
while((line=reader.readLine())!=null){
System.out.println(line);
}
System.out.println();
reader.close();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询