Java data lists

In this forum members can discuss topics about specific programming languages.
Post Reply
pr022
Posts: 2
Joined: Sat Jun 16, 2012 9:33 am

Java data lists

Post by pr022 »

Hi. I have been having trouble finding efficient ways to import data from an outside source in java, and projecteuler is making this problem more annoying for me. Some of the .txt files (especially 54, what i'm on right now) seem to be very difficult to use. I'm not sure if i'm getting my question across correctly -- specifically right now, i'm having trouble taking the information from a .txt file like poker.txt and putting it into a form for java to use. Any tips with this? Thanks :D

User avatar
jaap
Posts: 551
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Java data lists

Post by jaap »

Here's a simple bit of code to read a text file line by line.

Code: Select all

   public static void main(String[] args) throws IOException {
      BufferedReader br = new BufferedReader(new FileReader("poker.txt"));
      // read first line of text
      String s = br.readLine();
      while(s!=null){
         // do something with this line of text
         System.out.println(s);
         // read next line
         s = br.readLine();
      }
   }
You'll have to figure out what to do with each line yourself, but you may find that the String member functions charAt and split come in handy.

pr022
Posts: 2
Joined: Sat Jun 16, 2012 9:33 am

Re: Java data lists

Post by pr022 »

First..jaap? :D you have no idea how many time's i've been to your site. Thank you so much

And thanks for the answer - it was perfect! Kudos to you, mr. amazing

Post Reply