The Artima Developer Community
Sponsored Link

Java Answers Forum
some errors

1 reply on 1 page. Most recent reply: Jul 21, 2003 8:46 AM by Mr Plow

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Shuhadah Nor

Posts: 2
Nickname: shu
Registered: Jul, 2003

some errors Posted: Jul 21, 2003 1:04 AM
Reply to this message Reply
Advertisement
actually i'm not that good in java..
i want to write a program that can transfer data from one flat file(BOOKING.txt) to the other(Out.txt).the input data from BOOKING.txt are in this format:
@@0B2103071811250020007
and i have to output in in this format:
@@
0
B21
030718
112500
20007

and now this is my coding which have lots of errors..can anyone gives me any ideas in order to repair my program..



import java.io.*;

class Readfile{

private DataInputStream fileIn;
private String fileName;
private PrintStream output;



public void read(String fileName){
File fileIn = new File("C:\\BOOKING.txt");
try{
fileIn = new DataInputStream(new FileInputStream (fileName));
while(fileIn.readLine() != null)

output();
fileIn.close();

}
catch (IOException e2){
System.err.println("Error in file" + fileName + ":" + e2.toString());
System.exit(1);
}

}

public void output(){
String textOutput = fileIn.getText();
try{
output = new PrintStream(new FileOutputStream("C:\\Out.txt"));
output.print(fileIn);
output.close();
}
catch (IOException e2){
System.err.println("File Error:" + e2.toString());
System.exit(1);
}
}
}

class Application{
public static void main(String args[]) throws IOException{
Readfile RF = new Readfile();
RF.read(fileName);
RF.output();
}
}


Mr Plow

Posts: 18
Nickname: mrplow
Registered: Jun, 2003

Re: some errors Posted: Jul 21, 2003 8:46 AM
Reply to this message Reply
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);
	}
 
  }
};

Flat View: This topic has 1 reply on 1 page
Topic: J2EE engine stack Previous Topic   Next Topic Topic: JXTA PeerGroup Help!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use