forked from saemundur-haraldsson/CSCUT4Practical2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilesInOut.java
49 lines (47 loc) · 1.44 KB
/
FilesInOut.java
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
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.lang.Number;
/**
*
* CSCU9T4 Java strings and files exercise.
*
*/
public class FilesInOut {
public static void main(String[] args) {
//try and catch for full name file
try {
//creating files
File filein = new File ("input.txt");
File fileout = new File ("output.txt");
//creating scanner
Scanner in = new Scanner(filein);
//creating printer
PrintWriter printer = new PrintWriter(fileout);
System.out.println(args[0]);
//while loop to read scanner
while(in.hasNextLine()) {
String line = in.nextLine();
//uppercase the line by splitting
String[] newLine = line.split(" +");
String firstLetter = newLine[1];
firstLetter = firstLetter.toUpperCase() + ".";
newLine[1] = firstLetter;
line = String.join(" ", newLine);
System.out.println("this is the input file: "+ line);
//write line in output
printer.write(line);
System.out.println("this is the output file: " + line);
}
//closing scanner and printer
in.close();
printer.close();
} catch (FileNotFoundException e) {
System.out.println("File (input.txt) was not found");
e.printStackTrace();
}
}
// main
} // FilesInOut