File: Sample.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (75 lines) | stat: -rwxr-xr-x 1,787 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package driver;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
 * @author Brian Bushnell
 * @date Oct 13, 2015
 *
 * This class will read a file and write it to another file.
 *
 */
public class Sample {
	
	/** Primary method, called by java */
	public static void main(String[] args){

		String fnameIn=args[0];
		String fnameOut=args[1];
		
		BufferedReader br=getReader(fnameIn);
		PrintWriter pw=getWriter(fnameOut);
		
		try {
			processData(br, pw);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
		
		
	}
	
	/** Do stuff */
	static void processData(BufferedReader br, PrintWriter pw) throws IOException{
		for(String s=br.readLine(); s!=null; s=br.readLine()){
			//Parsing goes here
			pw.println(s);
		}
	}
	
	/** Fetches a BufferedReader, which allows line-by-line String iteration over text files */
	static BufferedReader getReader(String fname){
		FileInputStream fis=null;
		try {
			fis=new FileInputStream(fname);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		InputStreamReader isr=new InputStreamReader(fis);
		BufferedReader br=new BufferedReader(isr);
		return br;
	}
	
	/** Fetches a PrintWriter, which transforms Strings into a byte stream. */
	static PrintWriter getWriter(String fname){
		FileOutputStream fos=null;
		try {
			fos=new FileOutputStream(fname);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		BufferedOutputStream bos=new BufferedOutputStream(fos);
		PrintWriter pw=new PrintWriter(bos);
		return pw;
	}
	
}