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 8125807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:56:16+00:00 2026-06-06T06:56:16+00:00

I have a simple Java questions and I need a simple answer, if possible.

  • 0

I have a simple Java questions and I need a simple answer, if possible. I need to input the data from the file and store the data into an array. To do this, I will have to have the program open the data file, count the number of elements in the file, close the file, initialize your array, reopen the file and load the data into the array. I am mainly having trouble getting the file data stored as an array. Here’s what I have:

The to read file is here: https://www.dropbox.com/s/0ylb3iloj9af7qz/scores.txt

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.text.*;


public class StandardizedScore8
{



//Accounting for a potential exception and exception subclasses
public static void main(String[] args) throws IOException
{
    // TODO a LOT
    String filename;
    int i=0;


    Scanner scan = new Scanner(System.in);
    System.out.println("\nEnter the file name:");
    filename=scan.nextLine();



    File file = new File(filename);


    //File file = new File ("scores.txt");
    Scanner inputFile = new Scanner (file);

    String [] fileArray = new String [filename];
    //Scanner inFile = new Scanner (new File ("scores.txt"));

    //User-input
//  System.out.println("Reading from 'scores.txt'");
//  System.out.println("\nEnter the file name:");
//  filename=scan.nextLine();

    //File-naming/retrieving
//  File file = new File(filename);
//  Scanner inputFile = new Scanner(file);
  • 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-06T06:56:18+00:00Added an answer on June 6, 2026 at 6:56 am

    Yes, you can if you don’t care about the trouble of doing things twice. Use while(inputFile.hasNext()) i++;

    to count the number of elements and create an array:

    String[] scores = new String[i];
    

    If you do care, use a list instead of an array:

    List<String> list = new ArrayList<String>();
    while(inputFile.hasNext()) list.add(inputFile.next());
    

    You can get list elements like list.get(i), set list element like list.set(i,"string") and get the length of list list.size().

    By the way, your line of String [] fileArray = new String [filename];is incorrect. You need to use an int to create an array instead of a String.

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

Sidebar

Related Questions

i found many related questions here. I have a simple java program . it
I have Simple java program named MainController.java. Wehn I try to compile it from
I have a simple java code that reads text csv file that contains sentences
I have a simple Java class that I need to serialize to be stored
The question is simple, can I have the java source code (e.g. FooParser.java) generated
Simple question. I have a new list and an old list. In Java is
I have done simple java app for blackberry, while building am getting following error.
I have a simple Java class that has some methods: public class Utils {
I have a simple Java class in which I invoke a call to a
Alright, this is probably gonna be a pretty simple question to answer. I haven't

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.