Can someone tell me what this Java class does? I/O related

Posted by anon on Stack Overflow See other posts from Stack Overflow or by anon
Published on 2010-04-16T13:37:14Z Indexed on 2010/04/16 13:43 UTC
Read the original article Hit count: 228

Filed under:

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";

 }
}

© Stack Overflow or respective owner

Related posts about java