B
Bob
i have to make a program that creates a file called input.txt.
the user goes into this file and types a list of words in a line on
many lines
the program is suppose to make a file called output.txt that takes
every word from input.txt and displays one per line. words that are
made out of four letters get replaced to four stars, ****.
i did the program, the only problem is, it will only read the first
line of the input.txt file for some reason. Here is my code from the
reading of input.txt and writing of output.txt if u can tell me why it
won't read the second line in input.txt that owuld be great!
public static void readFile ()
{
String word = "", line = "";
BufferedReader input;
PrintWriter output;
try
{
input = new BufferedReader (new FileReader ("Input.txt"));
output = new PrintWriter (new FileWriter ("Output.txt"));
line = input.readLine ();
while (line != null)
{
try
{
for (int i = 0 ; i < line.length () ; i++)
{
if (line.charAt (i) == ' ')
{
if (word.length () == 4)
output.println ("****");
else
{
output.println (word);
}
word = "";
}
else
word += line.charAt (i);
}
if (word.length () == 4)
output.println ("****");
else
output.println (word);
line = input.readLine ();
output.close ();
} //end try
catch (NullPointerException e2)
{
}
} //end while != null
} //end try
catch (IOException e)
{
}
}
thnx a lot guys
the user goes into this file and types a list of words in a line on
many lines
the program is suppose to make a file called output.txt that takes
every word from input.txt and displays one per line. words that are
made out of four letters get replaced to four stars, ****.
i did the program, the only problem is, it will only read the first
line of the input.txt file for some reason. Here is my code from the
reading of input.txt and writing of output.txt if u can tell me why it
won't read the second line in input.txt that owuld be great!
public static void readFile ()
{
String word = "", line = "";
BufferedReader input;
PrintWriter output;
try
{
input = new BufferedReader (new FileReader ("Input.txt"));
output = new PrintWriter (new FileWriter ("Output.txt"));
line = input.readLine ();
while (line != null)
{
try
{
for (int i = 0 ; i < line.length () ; i++)
{
if (line.charAt (i) == ' ')
{
if (word.length () == 4)
output.println ("****");
else
{
output.println (word);
}
word = "";
}
else
word += line.charAt (i);
}
if (word.length () == 4)
output.println ("****");
else
output.println (word);
line = input.readLine ();
output.close ();
} //end try
catch (NullPointerException e2)
{
}
} //end while != null
} //end try
catch (IOException e)
{
}
}
thnx a lot guys