View Single Post
Old 03-10-2005, 11:21 PM   #1 (permalink)
crazyant
Registered User
 
Join Date: Mar 2005
Posts: 3
crazyant is on a distinguished road
Output problem with file manipulation (newbie)

I am going crazy.... I have a simple file I/O prog here that imports a txt file and then outputs that same text file with alternateing uppercase and lowcase lines. It works great except for at the very end of the program it adds a string "null" to the output. I can't seem to get rid of it.... what am i forgetting guys ?

Here is my source :
Code:
import java.io.*;

public class fetch
{
public static void main(String[] args) throws IOException
{

String in_file, out_file, Line_one;
PrintStream output_file;

System.out.print("Welcome to Anthony's UPPERCASE File "
+ "Converter!\n");
InputStreamReader reader =
new InputStreamReader(System.in);
BufferedReader keyboard =
new BufferedReader(reader);

System.out.println("Enter the input file name: ");

in_file = keyboard.readLine();
FileReader fReader = new FileReader(in_file);
BufferedReader inputFile = new BufferedReader(fReader);

Line_one = inputFile.readLine();

System.out.println("Enter your output file name: ");
out_file = keyboard.readLine();
output_file = new PrintStream(
new FileOutputStream(
new File(out_file)));


while(Line_one != null) //begin loop
{
System.out.println(Line_one.toUpperCase());
output_file.println(Line_one.toUpperCase());
Line_one = inputFile.readLine();
System.out.println(Line_one);
output_file.println(Line_one);
Line_one = inputFile.readLine();
}
System.out.print("Output file saved.\n");
// Close the file.
inputFile.close();
output_file.close();
}
}
and one output... the last line contains "null"

FRANKIE OWNED A
ferocious feline named
FREDDY AS A PET.
Freddy was funny and
FURRY.
His fur is bright red
WITH BLACK STRIPES.
null <----------------------------------------- THIS!!!! HELP PLEASE!!!!


Thanks in advance,

Anthony

Last edited by Belisarius; 03-11-2005 at 02:52 AM.
crazyant is offline   Reply With Quote