Results 1 to 11 of 11
Thread: CSV and split help
- 09-29-2012, 09:36 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
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 01:21 AM.
-
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.
- 09-30-2012, 01:23 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
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.
-
Re: CSV and split help
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.
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.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.
-
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?
- 09-30-2012, 02:34 AM #6
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: CSV and split help
Here are some of the lines.
- 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
-
Re: CSV and split help
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:
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.Java Code:String y = solar.get("Year"); String m = solar.get("Month"); String d = solar.get("Date"); String t = solar.get("Time");
- 09-30-2012, 02:51 AM #8
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: CSV and split help
It is because I'm trying to change the name from y to year.
-
- 09-30-2012, 02:57 AM #10
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: CSV and split help
Yes, it works. Thanks. I appreciate your help.
-
Similar Threads
-
.split()
By Lund01 in forum Advanced JavaReplies: 6Last Post: 06-28-2011, 03:24 PM -
Split a String with split()--Help
By danilson in forum New To JavaReplies: 7Last Post: 11-19-2010, 04:08 PM -
How to split a String using split function
By Java Tip in forum java.langReplies: 4Last Post: 04-17-2009, 08:27 PM -
How to split a String using split function
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks