wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Extracting data from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Extracting data from a file" Watch "Extracting data from a file" New topic
Author

Extracting data from a file

swanand hegde
Greenhorn

Joined: May 19, 2011
Posts: 6
I have a .dat file which has some 100 odd lines,i want to extract some 50 odd lines and put them in some memory (not a file) and the rest of the content in some other memory,like a buffer (again not in a file).The final output should have both the contents but some text must be inserted between them.There's also a field in .dat file which needs to be extracted and printed.


File.dat-->

some text(m1)
--> the 17 digit register no has to be extracted and printed ---
<tr style="FONT-FAMILY: Verdana; border: 1px #ffab00 solid; padding-right: 4px; empty-cells: show; "><td> Register no:12345678901234567</td></tr>




again some text(m2)





final output---> m1 (insert some text here) m2

Please reply fast,i need it urgently.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14157
    
  19


Welcome to the Ranch!

So, what exactly is your question: how to read a file (is it a text file that you want to read line by line?), how to find a specific piece of data in a string, ...? Have you written some code already yourself, and if yes, then where exactly do you get stuck - does it compile or not, does it run or not, do you get error messages? If yes, then what are the error messages? If you don't get an error message but it doesn't produce the output you expect, then how does what it actually does differ from what you expected?

Reading a file line by line is easy with a BufferedReader; see this example.

Searching for text in a string can be done with the methods in the String class (lookup the API documentation), or with regular expressions; see the java.util.regex package for that.

You'll most likely want to use a collection class such as ArrayList to keep the data in memory.

swanand hhhhhh wrote:Please reply fast,i need it urgently.

Please EaseUp

Also, please check your private messages for an administrative matter.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting data from a file