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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:25:25+00:00 2026-06-17T07:25:25+00:00

My csv is getting read into the System.out, but I’ve noticed that any text

  • 0

My csv is getting read into the System.out, but I’ve noticed that any text with a space gets moved into the next line (as a return \n)

Here’s how my csv starts:

first,last,email,address 1, address 2
john,smith,blah@blah.com,123 St. Street,
Jane,Smith,blech@blech.com,4455 Roger Cir,apt 2

After running my app, any cell with a space (address 1), gets thrown onto the next line.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class main {

    public static void main(String[] args) {
        // -define .csv file in app
        String fileNameDefined = "uploadedcsv/employees.csv";
        // -File class needed to turn stringName to actual file
        File file = new File(fileNameDefined);

        try{
            // -read from filePooped with Scanner class
            Scanner inputStream = new Scanner(file);
            // hashNext() loops line-by-line
            while(inputStream.hasNext()){
                //read single line, put in string
                String data = inputStream.next();
                System.out.println(data + "***");

            }
            // after loop, close scanner
            inputStream.close();


        }catch (FileNotFoundException e){

            e.printStackTrace();
        }

    }
}

So here’s the result in the console:

first,last,email,address 
1,address 
2
john,smith,blah@blah.com,123 
St. 
Street,
Jane,Smith,blech@blech.com,4455 
Roger 
Cir,apt 
2

Am I using Scanner incorrectly?

  • 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-17T07:25:26+00:00Added an answer on June 17, 2026 at 7:25 am
    scanner.useDelimiter(",");
    

    This should work.

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    
    
    public class TestScanner {
    
        public static void main(String[] args) throws FileNotFoundException {
            Scanner scanner = new Scanner(new File("/Users/pankaj/abc.csv"));
            scanner.useDelimiter(",");
            while(scanner.hasNext()){
                System.out.print(scanner.next()+"|");
            }
            scanner.close();
        }
    
    }
    

    For CSV File:

    a,b,c d,e
    1,2,3 4,5
    X,Y,Z A,B
    

    Output is:

    a|b|c d|e
    1|2|3 4|5
    X|Y|Z A|B|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulty getting R to read a .txt or .csv file that
I am running into an error using R's min() function. wip <- read.csv(WIP-01-11-11.csv) #
I'm having a lot of trouble getting data out of pig and into a
I'm trying to write a function to read csv contents into a datatable. I'm
I'm getting an error in Netbeans in my driver class on this line: System.out.print(Time
Task 1: Read each row from one csv file into one seprate txt file.
I am writing a program that should read in a number of csv files
I am trying to read a csv file with repeated row names but could
I'm trying to read a csv text file from S3 and then send each
I am converting about 4000 text files that contain HTML into MySQL database entries.

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.