Hi,
I dont understand why, but for some reason, the system does not recognize the buffered reader in the fileReverse method. Every time I try to invoke the readLine method on aBufferedReader, I get null as a result.
Even my file reads:
null
null
null
null
Can someone please help me figure out why?
Greatly appreciate it!
import java.io.*; //
public class ex9a {
public static int fileReverse(int countLine, FileInputStream aFileInputStream, FileOutputStream aFileOutputStream, BufferedReader aBufferedReader) throws IOException{
PrintStream coolPoet;
coolPoet = new PrintStream(aFileOutputStream);
int count;
for(count=0; count<countLine; count++){
String apoet;
apoet = aBufferedReader.readLine();
System.out.println(apoet);
}
if(countLine == 0){
aFileInputStream.close();
aFileOutputStream.close();
return countLine = 0;
}
else{
String aPoemLine;
aPoemLine = aBufferedReader.readLine();
coolPoet.println(aPoemLine);
countLine = fileReverse(countLine-1, aFileInputStream, aFileOutputStream, aBufferedReader);
return countLine;
}
}
public static void main(String args[]) throws IOException {
File apoem;
apoem = new File("src/infile.txt");
FileInputStream forInfile;
forInfile = new FileInputStream(apoem);
InputStreamReader readInfile;
readInfile = new InputStreamReader(forInfile);
BufferedReader bufferInfile, buffer;
bufferInfile = new BufferedReader(readInfile);
buffer = bufferInfile;
File robertFrost;
robertFrost = new File("src/Robert Frost.txt");
FileOutputStream outInfile;
outInfile = new FileOutputStream(robertFrost);
int lineNumber;
lineNumber = 0;
while(buffer.readLine() != null){
lineNumber++;
}
ex9a.fileReverse(lineNumber, forInfile, outInfile, bufferInfile);
}
}