Cat.java


1.    package futils;
2.    import java.util.*;
3.    import java.awt.*;
4.    import java.io.*;
5.    
6.    
7.    public final class Cat {
8.    
9.    private Cat() {}
10.    
11.          static public void javasToConsole2() {
12.              String[] files = Ls.getWildNames("java");
13.              for (int i=0; i < files.length; i++)
14.              	    fileToConsole(files[i]);
15.              }
16.          
17.    static public void javasToFile() throws IOException { 
18.    	String[] files = Ls.getWildNames("java");
19.              FileOutputStream fos = 
20.              	    Futil.getFileOutputStream();
21.              PrintWriter pw = new PrintWriter(fos);
22.              for (int i=0; i < files.length; i++)
23.              	fileToStream(files[i], pw);
24.              	    
25.              Futil.closeOutputStream(fos);
26.     }
27.          
28.    static public void fileToStream(String fileName, PrintWriter pw) throws IOException {
29.            BufferedReader br = new BufferedReader(
30.                    new FileReader(fileName));            	
31.            for (String line = br.readLine(); line != null; line=br.readLine())
32.                   	pw.println(line);     
33.            br.close();
34.       }
35.        
36.    static public void fileToConsole(String fileName) {
37.               try {
38.              	System.out.println("cat: "+fileName);
39.    	    	     FileReader fr = new FileReader(fileName);
40.                   	 String line;
41.                   	 BufferedReader br = new BufferedReader(fr);             	
42.                   	 while ((line = br.readLine()) != null)
43.                   	     	System.out.println(line);
44.                   	 br.close();
45.                 	} // try
46.                 	catch (Exception exe) {
47.                    	System.out.println("cat:Error on input file");
48.                    }         
49.          }
50.          
51.          }

[Back to Index]
This document was generated automatically by DiffCAD.