2 Replies - 476 Views - Last Post: 20 April 2009 - 08:47 PM Rate Topic: -----

#1 JoshMan6000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-April 09

Text Input

Posted 20 April 2009 - 08:16 PM

The work I have to do is make an application that allows us to open a file and make mark scores from it. But I dont understand how to input a file because of the code in my text book. Its very vauge in this subject and only has things like...
 try (BufferedReader reader = new BufferedReader( new FileReader(" name of the file")); 


What I dont understand is where all this goes and if the name of the file will directly open the text file.
Any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Text Input

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Text Input

Posted 20 April 2009 - 08:20 PM

I personally like to use Scanner when reading files. I can read in the line with a scanner, then convert it to a oduble or use the string however I like for what i need to do. Look into the Scanner class.
String aFile = "thename";
Scanner in = new Scanner(new File(aFile))
while(in.hasNextLine())
{
//your code here
}

Hope that little code helps start you off :)

Edit - Oops, change aFIle to String not File ty pbl. My bad xD

This post has been edited by Fuzzyness: 20 April 2009 - 08:54 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Text Input

Posted 20 April 2009 - 08:47 PM

String aFile = "thename";
Scanner in = new Scanner(new File(aFile))
while(in.hasNextLine())
{
//your code here
}

:D
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1