![]() |
Reading Files in Java problem
I am new to the Java language::: Any hard core java coders out there!
I need a Simple JAVA snippet that will take a reference file a, that has the following information : 0|TicketType 1|Version 2|TimeStamp 3|TimeZone of TimeStamp 4|Assignment1 5|Assignment2 6|Logical1 7|CorrelationType 8|CorrelationID 9|TicketSequenceID 10|DisconnectBFlag It should then pick a file b that is delimited with the | character, and print out the various fields as per reference file a. 1|34|2008.01.07 12:21:55|12|4|5-1-1254710754638|abc401|0|00000101A20200000008F8164781EF260C00|0|0|E00318FFFFBFFFFE|254710754638|16| So that the output is 0|TicketType = 1 1|Version = 34 2|TimeStamp = 2008.01.07 12:21:55 3|TimeZone of TimeStamp = 12 4|Assignment1 = 4 5|Assignment2 = 5-1-1254710754638 6|Logical1 = abc401 7|CorrelationType = 0 8|CorrelationID = 00000101A20200000008F8164781EF260C00 9|TicketSequenceID = 0 10|DisconnectBFlag = 0 many thanks |
Re: Reading Files in Java problem
What's that smell? I think I stepped in something. Smells like either dog shit, or homework. <sniff> Yup, definitely homework. Clean your own shoes off; don't ask us to do it for you.
Translation: Show you've first made an attempt on your own, or you're not likely to receive any help here. |
Re: Reading Files in Java problem
I agree with lectricpharaoh... at least show us you tried to resolve the problem yourself first.
|
Re: Reading Files in Java problem
this is what i have managed to pull.
import java.io.*; class FileRead { public static void main(String args[]) { try{ // Open the file that is the first command line parameter FileInputStream fstream = new FileInputStream("a.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println (strLine); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } class FileWrite { public static void main(String args[]) { try{ // Create file FileWriter fstream = new FileWriter("write_me.txt"); BufferedWriter out = new BufferedWriter(fstream); out.write("create new file and write into it!!/n"); //Close the output stream out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } |
Re: Reading Files in Java problem
:
Study the code a lot, and then rebuild it your own way, and then use that. |
| All times are GMT -5. The time now is 3:51 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC