Results 1 to 5 of 5
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Output from CSV file is messed up

    Hello everyone, I have been working on some code to read .csv files. So far I have been successful and I am able to read what's in the file,however the output is just a little messed up. The first row of the .csv file comes out like it was carriage returned or something despite there being no code telling it to do this.

    Now before you read the output of the file, I made a small program in C++ to generate the .csv file and write everything to it. When I was running the application I just typed random letters just to see if I could write to the .csv file. So most of what's in the rows will be gibberish. The only thing I care about is the first row.

    The output


    Serial
    number,Anode
    1,Anode
    2,Anode
    3,Anode
    4,Anode
    5,assembly
    lot
    number,capacitence,cathode
    lot
    number,ESR,head
    assembly
    number,Header
    Glassing
    Lot,Leakage,Tantalum
    lot
    number,Teflon
    Spacer
    1,Teflon
    Spacer
    2,Teflon
    Spacer
    3,Teflon
    Spacer
    Lot
    number,Serial
    number
    to
    kit <- everything after this point is okay
    1212,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1213,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1214,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1215,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1216,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1217,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1218,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1219,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1220,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1221,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1222,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1223,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1224,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1225,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1226,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1227,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1228,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1229,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1230,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1231,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1232,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1233,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1234,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1235,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1236,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1237,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1238,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1239,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1240,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1241,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1242,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1243,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1244,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1245,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1246,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1247,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1248,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1249,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1250,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht
    1251,gfhfk,gfhkgfk,fghkk,ghkgkfk,gfhkgfkghgf,ghkg, trhthdrh,drthrdhdr,drhdrhtdrth,drhdrhdrh,drhrhdrth ,dhdrhdtrhdh,hdrhdrhdrh,hdrhdrthtdr,rdhdrhrtd,drth rdth,drthrdhr,drhdrht


    I'm not sure why the first row is coming out all carriage returned as I didn'nt tell it to do that.

    Java Code:
    package csvreader;
    import java.io.File;
    import java.util.Scanner;
    import java.io.FileNotFoundException;
    /**
     *
     * @author natehindman
     */
    public class Csvreader {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String fileName = "somestuff5.csv";
            File file = new File(fileName);
            
           // Scanner inputStream = new Scanner(fileName);
            // TODO code application logic here
            try{
                Scanner inputStream = new Scanner(file);
                while(inputStream.hasNext()){
                    String data = inputStream.next();
                    System.out.println(data);
                }
                inputStream.close();
            }
       
            catch(FileNotFoundException e){
                System.out.printf("YOU DUN MESSED IT UP");
              //  e.printStackTrace;
            }
        }
        
    }
    Why is the first row of the output all messed up?
    Last edited by innovo; 07-10-2015 at 07:34 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Output from CSV file is messed up

    What do you expect hasNext() to do? The default delimiter is white space so that is probably your problem.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Re: Output from CSV file is messed up

    Quote Originally Posted by jim829 View Post
    What do you expect hasNext() to do? The default delimiter is white space so that is probably your problem.

    Regards,
    Jim
    What should I use instead?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Output from CSV file is messed up

    If you want a different delimiter to be used to separate tokens read by the next() method, use one of the Scanner class's methods to change it.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Output from CSV file is messed up

    Quote Originally Posted by innovo View Post
    What should I use instead?
    Read the documentation on Scanner to see ways of using alternate delimiters.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 08-05-2011, 09:21 PM
  2. Replies: 0
    Last Post: 09-30-2010, 08:16 PM
  3. Replies: 8
    Last Post: 05-12-2010, 07:19 PM
  4. Replies: 7
    Last Post: 11-19-2008, 02:09 PM
  5. I must be seriously messed up...
    By jpnym15 in forum New To Java
    Replies: 2
    Last Post: 11-16-2008, 07:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •