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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:06:43+00:00 2026-05-28T17:06:43+00:00

All I want to do is use the string variable for all my scanner

  • 0

All I want to do is use the string variable for all my scanner input.

public static void main(String[] args){
Scanner getInput = new Scanner(System.in);

String defaultInFile = "fileContainingEmails.txt";
String defaultOutFile = "copyPasteMyEmails.txt";

String myInFile;
String myOutFile;

    System.out.print("Enter input filename [default: " + defaultInFile + "]: ");
    //CRUD applications oh yea
    String myInputNom = getInput.nextLine();
    if (myInputNom.equals(""))
    {
        myInFile = defaultInFile;
    }
    else
    {   
        myInFile = myInputNom;
    }

    //System.out.println(defaultOutFile); THIS WORKS

    if (myInputNom.equals(""))
    {
        System.out.print("Enter output filename [default: " + defaultOutFile + "]: ");
    }
    else
    {
        System.out.print("Enter output filename [default: " + myInFile + "]: ");
    }

    //System.out.println("'" + myInputNom + "'");        

    myInputNom = getInput.nextLine();

    System.out.println("'" + myInputNom + "'"); 

    if (myInputNom.equals(""))
    {
        myOutFile = defaultOutFile;
    }
    else
    {
        myOutFile = myInputNom;
    }

    System.out.println("Input file: " + myInFile);
    System.out.println("Output file: " + myOutFile);
    }

So what am I doing wrong? The second getInput.nextLine(); acts like it ignores all input.

I expect something in myOutFile, but I get nothing.

Thanks!

  • 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-28T17:06:44+00:00Added an answer on May 28, 2026 at 5:06 pm

    Your code works fine here.

    % java -cp . foo
    Enter input filename [default: fileContainingEmails.txt]: df
    Enter output filename [default: df]: dfee
    'dfee'
    Input file: df
    Output file: dfee
    

    It’s actually a relief to try to help, only to discover that nothing is broken.

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

Sidebar

Related Questions

How can I use string argument input as a part of variable name in
I want to use PHP to check, if string stored in $myoutput variable contains
Below is my stored procedure. I want use stored procedure select all row of
I want all my pages to use have some viewdata. i need to get
We want to use the same user-id across all our dev tools, but this
I want all CSV files in a directory, so I use glob('my/dir/*.CSV') This however
Greetings to all... I want to use fade effect with jCarouselLite qualities. Is it
First of all, I don't want to use a join because that will make
What's the minimum JavaScript I need if all I want to do is use
Hay guys, i want to use something like this users = User.objects.all() but i

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.