Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting data from a file

 
swanand hegde
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic