Should've started by saying I'm completely new at coding, this is for a final exercise in class and that I have "hit a brick wall at warp 11" on this one.
Writing a program that will read an already created file, convert content to uppercase and then create a new file and write the uppercase content to it? Here are my class and main:
import java.io.*;
import java.util.*;
public class readfile{
private Formatter z;
private Scanner x;
public void openFile(){
try{
x = new Scanner(new File ("week8lowercaseinput.txt"));
}
catch(Exception e){
System.out.println("Couldn't find file");
}
}
public void readFile(){
while(x.hasNext()){
String a = x.next();
String d = a.toUpperCase();
System.out.printf("%s ", d);
}
}
public void createFile(){
try{
z = new Formatter( new File ("WEEK8UPPERCASEOUTPUT.txt"));
}
catch(Exception e){
System.out.println("Couldn't create file.");
}
//z.Format("%s ", d);
}
public void closeFile(){
x.close();
//z.close();
}
}
Main Class
import java.io.*;
import java.util.*;
import java.lang.*;
class TestReadFile{
public static void main(String[] args){
readfile a = new readfile();
a.openFile();
a.readFile();
a.createFile();
a.closeFile();
}
}
I'm able to open, read and convert content. I'm able to create a new file. The only thing that does not work is writing the converted content (uppercase) to new file. Any help would be greatly appreciated. Thank you.