DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: files

  1. #1
    lindsey Guest

    files


    this is most of the code that i am useing to get the numbers from the file.
    As you can see, i am already useing strings, but it is still reading the
    full line. I would like it to read one number at a time.

    FileReader theFile;
    BufferedReader fileIn;
    String oneLine;
    int [] unsort = new int [10];
    int n = 3;
    int r = 1;
    try{
    theFile = new FileReader( fileName);
    fileIn = new BufferedReader ( theFile );
    while ( (oneLine = fileIn.readLine()) !=null){
    unsort[r] = Integer.parseInt(oneLine);

    }
    System.out.println( unsort[1]);
    }
    catch(Exception e){
    { System.out.println (e); }
    }

  2. #2
    John Guest

    Re: files


    Your parsing is looking for spaces. Why dont you use oneLine.charAt(index)
    and typecast it as an int.

    "lindsey" <zave4@aol.com> wrote:
    >
    >this is most of the code that i am useing to get the numbers from the file.
    > As you can see, i am already useing strings, but it is still reading the
    >full line. I would like it to read one number at a time.
    >
    > FileReader theFile;
    > BufferedReader fileIn;
    > String oneLine;
    > int [] unsort = new int [10];
    > int n = 3;
    > int r = 1;
    > try{
    > theFile = new FileReader( fileName);
    > fileIn = new BufferedReader ( theFile );
    > while ( (oneLine = fileIn.readLine()) !=null){
    > unsort[r] = Integer.parseInt(oneLine);
    >
    > }
    > System.out.println( unsort[1]);
    > }
    > catch(Exception e){
    > { System.out.println (e); }
    > }



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links