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

  • SEARCH
  • Home
  • 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 6476645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:50:59+00:00 2026-05-25T06:50:59+00:00

I am going through the inputStream and checking if the first input of the

  • 0

I am going through the inputStream and checking if the first input of the file has the valid input but the problem is if it doesn’t I call my method to read in file again but it still has the information from the previous scan of the file. Is there anyway I can tell it to just reset what was in the inputStream and start all over again ?

 public static  void readinfile(ArrayList<ArrayList> table,
        int numberOfColumns,  
        ArrayList<String> header, ArrayList<ArrayList<String>> original,
        ArrayList<String> sntypes, ArrayList<Integer> displaySize, ArrayList<String> writeOut, Scanner inputStream) 
{

    inputStream = null;
     table.clear(); 
    sntypes.clear();
    displaySize.clear();
    header.clear();
    numberOfColumns = 0;
    original.clear();
    Scanner keyboard = new Scanner(System.in);
    String fileName = keyboard.nextLine();
    System.out.println(inputStream);
    boolean done = false;
    while(!done)
    {
        try 
        {
            inputStream = new Scanner(new FileInputStream(fileName));
            done = true;

            header.clear();
        }
        catch(FileNotFoundException E)
        {   System.out.println("Error in opening file ");
        System.out.print("enter data file: ");
            fileName = keyboard.nextLine();

        }
    }

    // file is now open and input scanner attached
    boolean done1 = false;
    if ( inputStream.hasNextLine() ) {

        String csvLine = inputStream.nextLine();

        Scanner lineparse = new Scanner(csvLine);
        lineparse.useDelimiter(",");
        ArrayList<String> rowOne = new ArrayList<String>();

        while (lineparse.hasNextLine()) {
            String temp = lineparse.next();
            String originaltemp = temp; 
            writeOut.add(temp);
            temp = temp + "(" + (++numberOfColumns) + ")";
            displaySize.add(temp.length());


            if (temp.trim().substring(0, 2).equalsIgnoreCase("S ")
                    || temp.trim().substring(0, 2).equalsIgnoreCase("N ")) {
                rowOne.add(originaltemp);
                header.add(temp.substring(2));
                sntypes.add(temp.toUpperCase()
                        .substring(0,2).trim());

            } else {

                System.out
                .println("Invalid file please enter a new file: ");
                readinfile(table, numberOfColumns, header,
                    original, sntypes,displaySize, writeOut, inputStream );

            }

        }
        // add table here it gives problem later on...
        original.add(rowOne);

    }

    while (inputStream.hasNextLine()) 
    {
        String csvLine = inputStream.nextLine();

        Scanner lineparse = new Scanner(csvLine);
        lineparse.useDelimiter(",");

        ArrayList row = new ArrayList();
        int j = 0;
        while (lineparse.hasNext()) {
            String temp = lineparse.next().trim();

            int sizeOfrow = temp.trim().length();
            if (sizeOfrow > displaySize.get(j))
            {
                displaySize.set(j, sizeOfrow);
            }
            if (j < numberOfColumns && sntypes.get(j).equalsIgnoreCase("N")) {
            try 
                {
                    if(temp.equalsIgnoreCase(""))
                    {
                        row.add(new Double(0.0));   
                    }
                    else
                    {   
                        row.add(new Double(temp.trim()));
                    }
                }

            catch (NumberFormatException E)
                {
                    System.out.println("Opps there is a mistake I was expecting a number and I found: "+temp);
                    System.out.println("This row will be ignored");
                    break;

                }

            }
            else 
            {
                if(temp.equalsIgnoreCase(""))
                {
                    row.add((" "));
                }else
                {
                    row.add(temp);
                }

            }
            j++;
        }

        if (row.size() == numberOfColumns) 
        {
            table.add(row);
        }
    }// close for while


    inputStream.close();
}
  • 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-05-25T06:50:59+00:00Added an answer on May 25, 2026 at 6:50 am

    You’re calling the method recursively – which is actually not ideal, but we’ll leave that for the moment (the method is also way longer than is good for maintainability) – but the problem is that after you’ve made the recursive call and it’s completed, you’re still continuing with the original scanner. I suspect if you just add a return; statement after the recursive call, it will be fine.

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

Sidebar

Related Questions

Just going through the sample Scala code on Scala website, but encountered an annoying
Going through the SproutCore Getting started tutorial and have a problem. Inside the Todos.todoListController
While going through a WP7.5 background transfer service policy, one can read the following:
Going through a weird problem here. I am trying to get the date of
Im going through a log file using php and it looks either like this:
Im going through Apple's OSX Cocoa (Your First Mac Application) tutorial and am up
Going through some of my older Delphi projects and upgrading them to D2009, as
Going through Javascript documentation, I found the following two functions on a Javascript object
Going through the microsoft authentication tutorial listed here they have you create a master
While going through university and from following the development of SO, I've heard a

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.