files


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: files

Hybrid View

  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); }
    > }



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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center