2 Replies - 352 Views - Last Post: 26 October 2010 - 09:35 AM Rate Topic: -----

#1 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Reading in a File to a program.

Posted 26 October 2010 - 08:38 AM

This is not homework just a side project for myself.

I need to read in a file that starts out with 10 (the number of quotes I have) followed by all my quotes.I am going to use %% to indicate the start of a new quote. The user should be able to input 7 and it will go to the 7th quote (just a FYI for ways to read the file in).

How would I go about doing this?

I was going to use
File file = new File("C:\\MyFile.txt");


but what do you guys think would be the best way to read this in and be able to go to the quote that's desired?

Thanks for your input,
push

Is This A Good Question/Topic? 0
  • +

Replies To: Reading in a File to a program.

#2 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Reading in a File to a program.

Posted 26 October 2010 - 09:23 AM

Well, you have a file now.

You're going to need a FileReader next.

You'll be using that to do your parsing and whatnot. Read up on some tutorials regarding that to see how it's used.

Scanner can also be used as well.

This post has been edited by SarumanTheWhite: 26 October 2010 - 09:26 AM

Was This Post Helpful? 1
  • +
  • -

#3 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Reading in a File to a program.

Posted 26 October 2010 - 09:35 AM

in your case, if the quotes are in lines, use BufferedReader.readLine()or Scanner.nextLine() Check out the Java API

This post has been edited by Luckless: 26 October 2010 - 09:36 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1