Can someone tell me what this Java class does? I/O related
- by anon
I am relatively new to Java and trying to learn the I/O syntax. Could someone give me a general overview of what this code does? Thanks!!
import java.io.*;
public class FileReader {
private String openFile="";
private String saveFile="";
FileReader(openFile, saveFile)
{
this.openFile=openFile;
this.saveFile=saveFile;
}
public String process(){
System.out.println(this.openFile);
System.out.println(this.saveFile);
BufferedReader open=null;
FileReader openFR=null;
FileWriter save=null;
int counter=0;
String output="";
if(openFile.equals("")){
return "No open file specifified\n";
}
if(this.saveFile.equals("")){
return "No save file specified\n";
}
try {
openFR = new FileReader(this.openFile);
open = new BufferedReader(openFR);
} catch (FileNotFoundException e) {
return ("Open file no longer exists\n");
}
try {
save = new FileWriter(saveFile);
}
catch (IOException e){
return ("Error saving the file\n");
}
try{
String temp = open.readLine();
while(temp != null){
temp = open.readLine();
counter++;
save.write(output + "\n");
}
} catch (IOException e){
e.getStackTrace();
return ("Error reading open file");
}
try {
save.flush();
} catch (IOException e) {
e.printStackTrace();
return ("Error writing save file");
}
return "Operation completed successfully";
}
}