Mr Plow
Posts: 18
Nickname: mrplow
Registered: Jun, 2003
|
|
Re: some errors
|
Posted: Jul 21, 2003 8:46 AM
|
|
import java.io.*;
public class ReaderWriter
{
public static void main(String[] args)
{
String contents = new String();
//Read the contents of the first file into a String
try
{
BufferedReader input = new BufferedReader(new FileReader("BOOKING.TXT"));
String str;
while( (str = input.readLine()) != null)
contents += str + "\n";
input.close();
} catch (IOException e) {
System.err.println("Error throw while reading contents of the BOOKING.txt file: " + e);
}
//Change line breaks in the contents String
String line1, line2, line3, line4, line5, line6;
line1 = contents.substring(0, 2);
line2 = contents.substring(2, 3);
line3 = contents.substring(3, 6);
line4 = contents.substring(6, 12);
line5 = contents.substring(12, 18);
line6 = contents.substring(18);
//Place the contents of the BOOKING.TXT file into the contents String with the correct line breaks
contents = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6;
//Write the values in the contents String out to the OUT.txt file
try
{
BufferedReader input = new BufferedReader(new StringReader(contents));
PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("OUT.txt")));
String str;
while ((str = input.readLine()) != null)
{
output.println(str);
}
output.close();
input.close();
} catch (IOException e) {
System.err.println("Error thrown while writing out to OUT.txt file: " + e);
}
}
};
|
|