![]() |
| ||
| Read a specific line from a text file - how to ? hi there! how do i read a specific line from a text file? maybe im asking the wrong question, so i will try to explain what im trying to do :) i have a file that looks a bit like this(just with 1000 lines): 1 dudea addressa 1000 10000000 maila 2007-11-19 2 dudeb addressb 2000 20000000 mailb 2007-11-19 3 dudec addressc 3000 30000000 mailc 2007-11-19 4 duded addressd 4000 40000000 maild 2007-11-19 5 dudee addresse 5000 50000000 maile 2007-11-19 as you can probably see its: ID name address zipcode phonenumber mail date now i need to get this stuff into a 2d array.. i know its something with tokenizer or something like that, but i spent like 3 million hours on this annoying little issue and i just cant figure it out! so please! someone help me :) |
| ||
| Re: Read a specific line from a text file - how to ? You can use Scanner or a BufferedReader and String.split(). |
| ||
| Re: Read a specific line from a text file - how to ? im quite new to java, so my next question is: what is that and how do i use it ? :p |
| ||
| Re: Read a specific line from a text file - how to ? http://java.sun.com/javase/6/docs/ap...l/Scanner.html can be used for scanning and processing many kinds of text input from a variety of sources. http://java.sun.com/javase/6/docs/ap...redReader.html allows for buffered reading from an input stream and has a readLine() method that will read a single line from a stream (file in your case). String.split() http://java.sun.com/javase/6/docs/ap...va.lang.String) splits a string by the supplied expression and returns the pieces as an array of strings. The following code fragment opens a BufferedReader against a text file and reads each line. try {With that as a starting point, see if you can get the elements into your array and post back if you run into problems. |
| ||
| Re: Read a specific line from a text file - how to ? thanks! i think that bit of code solved half of my problem.. i will read those link and try to figure it out.. great forum btw.. definitely worth a bookmark :) |
| All times are GMT -4. The time now is 2:16 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC