forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTest.java
More file actions
50 lines (43 loc) · 1.49 KB
/
FileTest.java
File metadata and controls
50 lines (43 loc) · 1.49 KB
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
import java.io.*;
import java.util.*;
public class FileTest {
public static void main(String args[]) {
try {
File input = new File("C:/Users/srinath/Desktop/input.txt");
File output = new File("C:/Users/srinath/Desktop/output.txt");
// System.out.println("hello");
Scanner sc = new Scanner(input);
//PrintWriter printer = new PrintWriter(output);
FileWriter ff=new FileWriter(output,true); // for appending the output file
BufferedWriter buffer=new BufferedWriter(ff);
PrintWriter printer = new PrintWriter(buffer);
// Read and write operation
String line;
String[] strs;
while(sc.hasNextLine()) {
String s = sc.nextLine();
line=s;
//printer.println();
//printer.write(s);
//printer.println();
strs = line.trim().split("\\s+");
for(int i=0;i<strs.length;i++){
System.out.println(strs[i]);
printer.write(strs[i]);
printer.print("\t");
}
printer.println();
}
printer.flush();
printer.close();
ff.close();
sc.close();
}
catch(FileNotFoundException e) {
System.err.println("File not found. Please scan in new file.");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}