Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:51:05+00:00 2026-06-12T11:51:05+00:00

I’m a bit stumped on how to go about doing this right. I got

  • 0

I’m a bit stumped on how to go about doing this right. I got some ways into it and now I’m waist deep. So what I want to do is parse a text file with a bunch of number two on each line like this.

1 10
2 12 
3 13 

etc….

Each one is split by one space. I have gotten that far I even got it to assign the correct number to the variables in the object. My thing is it keep overwriting the array and won’t fill in the rest of it with the data from the text file. I think it should print off the text file basically if I print off the array.

public static void main(String[] args) {
      
    Process [] pArray;
    //just need to have 10 Process
    pArray = new Process [10];
    
    //delimiter to parse string
    String delimiter = " ";
    String[] tokens;
    tokens = new String [10];
    
    /*
     * save this for input handeling
    Scanner input = new Scanner( System.in );
    System.out.println("Enter the Text file for data set");
    String fileDestination = input.next();
    * */
    
    //get data from the file
    File file = new File("C:/Users/Kenshin/Desktop/TestData.txt");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    try {
  
        fis = new FileInputStream(file);     
        // Here BufferedInputStream is added for fast reading.     
        bis = new BufferedInputStream(fis);   
        dis = new DataInputStream(bis);    
        // dis.available() returns 0 if the file does not have more lines.    
        while (dis.available() != 0) {   
            // this statement reads the line from the file and print it to       
            // the console.        
            int g = 0;
            //System.out.println(dis.readLine());
            tokens = dis.readLine().split(delimiter);
            int aInt = Integer.parseInt(tokens[0]);
            int bInt = Integer.parseInt(tokens[1]);
            for( int i = 0; i < tokens.length; i ++)
            {
                
                //int aInt = Integer.parseInt(tokens[i]);
                pArray[g] = new Process(aInt, bInt);
                
            }
          
            g++;
            
        }
  
        // dispose all the resources after using them.     
        fis.close();     
        bis.close();
        dis.close();
    } catch (FileNotFoundException e) {  
        e.printStackTrace();
    } catch (IOException e) {  
        e.printStackTrace();
    }
    
    for(int i = 0; i < pArray.length; i ++)
    {
        System.out.print(pArray[i].arrivalTime + " ");
        System.out.println(pArray[i].burstTime);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:51:07+00:00Added an answer on June 12, 2026 at 11:51 am

    Don’t you need to do this

    int g = 0;
    

    outside your loop ? Otherwise you’re continually rewriting your initial value in the array and not advancing the value (populating the rest of the array).

    To make this simpler, I would populate a ArrayList<Process> or other similar collection rather than a fixed-length array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.