#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0

    Java not reading in CSV file


    Hello all,

    I am trying to read in a CSV file. When I use the following code with one .csv file, it works fine, but when I use "Sample_TRN.csv", java won't print anything. Here's the code I'm working with:

    Code:
    //tftm.java
    
    
    
    
    
    import java.io.*;
    
    import java.util.Arrays;
    
    import java.util.ArrayList;
    
    import java.util.List;
    
    import java.util.regex.*;
    
    
    
    
    
    
    
    public class tftm{
    
    
    
     public static void main(String[] arg) throws Exception {
    
    
    
    BufferedReader b1 = 
    
    	new BufferedReader(new FileReader("Sample_TRN.csv"));//This reads in information from the file "Sample_TRN.csv".
    
    
    
    BufferedWriter b2 = 
    
    	new BufferedWriter(new FileWriter("TF_target_map.txt"));//
    
    
    
    
    
    
    
    String strRead; String strWrite;
    
    
    
    
    
    while ((strRead=b1.readLine())!=null){
    
     String splitarray[] = strRead.split(",");
    
     String tf = splitarray[0];//This defines "tf" as everything in column 0 of "Sample_TRN.csv".
    
    
    
    b2.write(tf);
    
    
    
        
    
    
    
          
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
     } 
    
    }
    Here's "Sample_TRN.csv" :

    Code:
    RSP_0489,RSP_3168,,+
    
    RSP_0489,RSP_3169,,+
    
    RSP_0489,RSP_3170,,+
    
    RSP_0489,RSP_3171,,+
    
    RSP_0489,RSP_3172,,-
    
    RSP_0507,RSP_0495,,-
    
    RSP_0507,RSP_0496,,-
    
    RSP_0507,RSP_0497,,-
    
    RSP_0507,RSP_0499,,-
    
    RSP_0507,RSP_0500,,-
    
    RSP_0507,RSP_0501,,-
    
    RSP_0507,RSP_0502,,-
    
    RSP_0507,RSP_0503,,-
    
    RSP_0507,RSP_0504,,-
    
    RSP_0507,RSP_0505,,-
    
    RSP_0507,RSP_0506,,-
    
    RSP_0507,RSP_0507,,-
    
    RSP_0507,RSP_0508,,-
    
    RSP_0507,RSP_0509,,-
    
    RSP_0547,RSP_0309,Absence of Oxygen,+
    
    RSP_0547,RSP_0310,Absence of Oxygen,+
    
    RSP_0547,RSP_0527,Absence of Oxygen,+
    
    RSP_0547,RSP_1601,Absence of Oxygen,+
    
    RSP_0547,RSP_1762,Absence of Oxygen,+
    
    RSP_0547,RSP_2010,Absence of Oxygen,+
    
    RSP_0547,RSP_2346,Absence of Oxygen,+
    
    RSP_0547,RSP_2347,Absence of Oxygen,+
    
    RSP_0547,RSP_3306,Absence of Oxygen,+
    
    RSP_0547,RSP_3401,Absence of Oxygen,+
    
    RSP_0547,RSP_4072,Absence of Oxygen,+
    
    RSP_0601,RSP_0152,Presence of Oxygen,+
    
    RSP_0601,RSP_1025,Presence of Oxygen,+
    
    RSP_0601,RSP_1026,Presence of Oxygen,+
    
    RSP_0601,RSP_1258,Presence of Oxygen,+
    
    RSP_0601,RSP_1542,Presence of Oxygen,+
    
    RSP_0601,RSP_1546,Presence of Oxygen,+
    
    RSP_0601,RSP_1591,Presence of Oxygen,+
    
    RSP_0601,RSP_1956,Presence of Oxygen,+
    
    RSP_0601,RSP_2294,Presence of Oxygen,+
    
    RSP_0601,RSP_2314,Presence of Oxygen,+
    
    RSP_0601,RSP_2388,Presence of Oxygen,+
    
    RSP_0601,RSP_2389,Presence of Oxygen,+
    
    RSP_0601,RSP_3075,Presence of Oxygen,+
    
    RSP_0601,RSP_3076,Presence of Oxygen,+
    
    RSP_0601,RSP_3272,Presence of Oxygen,+
    
    RSP_0601,RSP_3537,Presence of Oxygen,+
    
    RSP_0601,RSP_4209,Presence of Oxygen,+
    
    RSP_0611,RSP_0418,,
    
    RSP_0611,RSP_2228,,
    
    RSP_0611,RSP_2346,,
    
    RSP_0611,RSP_2347,,
    
    RSP_0611,RSP_2913,,
    
    RSP_0611,RSP_2961,,
    
    RSP_0611,RSP_2976,,
    
    RSP_0611,RSP_4072,,
    etc.

    I think the error occurs right the last "Presence of Oxygen" line. What's going on??

    Thanks,

    Kmath
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Are there any error messages on the console when the code executes?

    won't print anything
    Where does the code print anything? I don't see any print statements in it.

    Where is the output file closed?
    Last edited by NormR; June 14th, 2013 at 06:49 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    I mean it didn't "write" anything with BufferedWriter. Anyway I replaced the blank spaces in the CSV file with " " (a space) and that solved the issue. Thanks anyway

IMN logo majestic logo threadwatch logo seochat tools logo