Debian Codegraph @

current/driver/Sample.java

raw symbols SCIP
1 package driver;
2
3 import java.io.BufferedOutputStream;
4 import java.io.BufferedReader;
5 import java.io.FileInputStream;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.io.InputStreamReader;
9 import java.io.PrintWriter;
10
11 /**
12 * @author Brian Bushnell
13 * @date Oct 13, 2015
14 *
15 * This class will read a file and write it to another file.
16 *
17 */
18 public class Sample {
19
20 /** Primary method, called by java */
21 public static void main(String[] args){
22
23 String fnameIn=args[0];
24 String fnameOut=args[1];
25
26 BufferedReader br=getReader(fnameIn);
27 PrintWriter pw=getWriter(fnameOut);
28
29 try {
30 processData(br, pw);
31 } catch (IOException e) {
32 e.printStackTrace();
33 System.exit(1);
34 }
35
36
37 }
38
39 /** Do stuff */
40 static void processData(BufferedReader br, PrintWriter pw) throws IOException{
41 for(String s=br.readLine(); s!=null; s=br.readLine()){
42 //Parsing goes here
43 pw.println(s);
44 }
45 }
46
47 /** Fetches a BufferedReader, which allows line-by-line String iteration over text files */
48 static BufferedReader getReader(String fname){
49 FileInputStream fis=null;
50 try {
51 fis=new FileInputStream(fname);
52 } catch (Exception e) {
53 e.printStackTrace();
54 System.exit(1);
55 }
56 InputStreamReader isr=new InputStreamReader(fis);
57 BufferedReader br=new BufferedReader(isr);
58 return br;
59 }
60
61 /** Fetches a PrintWriter, which transforms Strings into a byte stream. */
62 static PrintWriter getWriter(String fname){
63 FileOutputStream fos=null;
64 try {
65 fos=new FileOutputStream(fname);
66 } catch (Exception e) {
67 e.printStackTrace();
68 System.exit(1);
69 }
70 BufferedOutputStream bos=new BufferedOutputStream(fos);
71 PrintWriter pw=new PrintWriter(bos);
72 return pw;
73 }
74
75 }