Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default CSV and print help.

    I'm trying to get my data to populate the specific criteria but all I am getting when it prints out is ": : :".

    Here is my code:
    Java Code:
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    import com.csvreader.CsvReader;
    
    public class SolarDateTime {
    
    	public static void main(String[] args) {
    		try {
    			
    			CsvReader solar = new CsvReader("solar.txt");
    		
    			solar.readHeaders();
    
    			while (solar.readRecord())
    			{
    				String y = solar.get("Year");
    				String m = solar.get("Month");
    				String d = solar.get("Date");
    				String t = solar.get("Time");
    				
    				
    				// perform program logic here
    			System.out.println(y + ":"+ m + ":" + d + ":" + t);
    			}
    	
    			solar.close();
    			
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		
    	}
    
    }
    Last edited by LostinThoughts; 09-30-2012 at 02:21 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    I'm sorry, what is your question? Also, you should respond to the folks who answered your previous question on this site.

  3. #3
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: CSV and split help

    I apologize I thought I added the code but now I did and I do not know how to solve/close my previous question on this site.

    As for my new question I'm just trying to have my info print with the txt I'm pulling from but nothing is showing up but ": : :" when I print.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    Quote Originally Posted by LostinThoughts View Post
    I apologize I thought I added the code but now I did and I do not know how to solve/close my previous question on this site.
    Just mention that it's solved should be enough at this point. Again, consider thanking the folks who volunteered time to help you. They will greatly appreciate it I'm sure.

    As for my new question I'm just trying to have my info print with the txt I'm pulling from but nothing is showing up but ": : :" when I print.
    This question is a bit tricky for us since it involves something we're not familiar with including a 3rd party library that is outside of Java, CsvReader, as well as a data file that we're not privy to. You may get lucky and find someone who is familiar with this library, but in all likelihood you probably won't, sorry.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    I've found the CsvReader API here. Can you post your data file? At least the first 10 lines of it?

  6. #6
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: CSV and split help

    Here are some of the lines.
    1. y,m,d,t,Incremental Generation Energy (kWh),Incremental Building Demand (kWh),Incremental Insolation (kWh/M^2),Last Generation Energy (kWh),Last Insolation (kWh/M^2),Average Generation Power (kW),Average Irradiance (W/M^2),Average Ambient Temperature (C),Average Cell Temperature (C)
      2012,8,11,00:00,-0.258,null,null,412854.167,null,-0.243,null,null,null
      2012,8,11,01:00,-0.248,null,null,412853.919,null,-0.252,null,null,null
      2012,8,11,02:00,-0.256,null,null,412853.663,null,-0.248,null,null,null
      2012,8,11,03:00,-0.246,null,null,412853.417,null,-0.255,null,null,null
      2012,8,11,04:00,-0.248,null,null,412853.169,null,-0.255,null,null,null
      2012,8,11,05:00,-0.244,null,null,412852.925,null,-0.245,null,null,null
      2012,8,11,06:00,-0.276,null,null,412852.649,null,-0.275,null,null,null
      2012,8,11,07:00,4.088,null,null,412856.737,null,4. 193,null,null,null

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    Quote Originally Posted by LostinThoughts View Post
    Here are some of the lines.
    [list=Option]
    y,m,d,t,Incremental Generation Energy (kWh),Incremental Building Demand (kWh),Incremental Insolation (kWh/M^2),Last Generation Energy (kWh),Last Insolation (kWh/M^2),Average Generation Power (kW),Average Irradiance (W/M^2),Average Ambient Temperature (C),Average Cell Temperature (C)
    This is enough and shows what you're doing wrong. Note the column headers present in the first line of the data file. Now note what column header Strings you're trying to use in the get method parameter to extract your data:

    Java Code:
                    String y = solar.get("Year");
                    String m = solar.get("Month");
                    String d = solar.get("Date");
                    String t = solar.get("Time");
    Do you notice what is wrong and why this code won't work? I'm betting that if you use the correct column headers (or column indexes), your problem will be solved.

  8. #8
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: CSV and split help

    It is because I'm trying to change the name from y to year.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    Quote Originally Posted by LostinThoughts View Post
    It is because I'm trying to change the name from y to year.
    OK good, and so you've solve your problem now, right? The new code works?

  10. #10
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: CSV and split help

    Yes, it works. Thanks. I appreciate your help.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: CSV and split help

    Quote Originally Posted by LostinThoughts View Post
    Yes, it works. Thanks. I appreciate your help.
    Great, and you're welcome!

Similar Threads

  1. .split()
    By Lund01 in forum Advanced Java
    Replies: 6
    Last Post: 06-28-2011, 04:24 PM
  2. Split a String with split()--Help
    By danilson in forum New To Java
    Replies: 7
    Last Post: 11-19-2010, 05:08 PM
  3. How to split a String using split function
    By Java Tip in forum java.lang
    Replies: 4
    Last Post: 04-17-2009, 09:27 PM
  4. How to split a String using split function
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:32 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
  •