Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 13th, 2008, 10:53 PM   #1
domquem
Newbie
 
Join Date: Jun 2005
Posts: 7
Rep Power: 0 domquem is on a distinguished road
Send a message via Yahoo to domquem
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
domquem is offline   Reply With Quote
Old Jan 14th, 2008, 3:53 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5 lectricpharaoh will become famous soon enough
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jan 15th, 2008, 8:46 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Re: Reading Files in Java problem

I agree with lectricpharaoh... at least show us you tried to resolve the problem yourself first.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 18th, 2008, 6:40 AM   #4
domquem
Newbie
 
Join Date: Jun 2005
Posts: 7
Rep Power: 0 domquem is on a distinguished road
Send a message via Yahoo to domquem
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());
}
}
}
domquem is offline   Reply With Quote
Old Jan 18th, 2008, 10:03 AM   #5
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 80
Rep Power: 1 null_ptr0 is on a distinguished road
Re: Reading Files in Java problem

java Syntax (Toggle Plain Text)
  1. import java.io.FileInputStream;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5.  
  6. public class Main {
  7. private void printOutput() throws AssertionError {
  8. String[] aLines = getALines();
  9. String[] bValues = getBValues();
  10. assert (aLines.length == bValues.length)
  11. : "Number of lines and values not same";
  12. for (int i = 0; i < aLines.length; ++i) {
  13. System.out.println(aLines[i] + " = " + bValues[i]);
  14. }
  15. }
  16.  
  17. public String[] getALines() {
  18. try {
  19. BufferedReader bufferedReader =
  20. new BufferedReader(new FileReader("./a.txt"));
  21. ArrayList<String> stringList = new ArrayList<String>();
  22. for (String sLine = bufferedReader.readLine();
  23. sLine != null; sLine =
  24. bufferedReader.readLine()) {
  25. stringList.add(sLine);
  26. }
  27. bufferedReader.close();
  28. return (String[])
  29. stringList.toArray(new String[stringList.size()]);
  30. } catch (IOException ioex) {
  31. ioex.printStackTrace();
  32. }
  33. return null;
  34. }
  35.  
  36. public String[] getBValues() {
  37. try {
  38. FileInputStream fileInputStream =
  39. new FileInputStream("./b.txt");
  40. byte[] buf = new byte[fileInputStream.available()];
  41. fileInputStream.read(buf, 0, buf.length);
  42. fileInputStream.close();
  43. return new String(buf).split("|");
  44. } catch (IOException ioex) {
  45. ioex.printStackTrace();
  46. }
  47. return null;
  48. }
  49.  
  50. public static void main(String[] argv) {
  51. new Main().printOutput();
  52. }
  53. }
Heres what 3 minutes gave m.
Study the code a lot, and then rebuild it your own way, and then use that.
__________________
iload_0 iconst_1 ishl or
iload_0 iconst_2 idiv or
iload_0 iconst_2 iconst_1 imul idiv
[1] & [2] use the smallest stack size
null_ptr0 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. I got a problem in making Java games .. bratsercom Java 11 Oct 1st, 2007 2:31 PM
reading in a file in java ryanl Java 3 Sep 8th, 2005 9:54 AM
Java script problem zeotrex JavaScript and Client-Side Browser Scripting 5 Sep 2nd, 2005 5:30 AM
Reading Files, and Formating brokenhope C++ 6 Apr 18th, 2005 4:01 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC