reset password
Author Message
Darren76
Posts: 39
Posted 12:09 Feb 16, 2016 |

would it be acceptable to use a text file instead of using csv file for HW 3?  I want to convert the csv file to a text file to complete the hw. 

comlor
Posts: 16
Posted 12:15 Feb 16, 2016 |

Why do you want to do that?  A csv file is a text file, the difference being that, each line in a csv file contains specific data set separated by commas.  If you change the file to a txt extension you basically change nothing but the physical addressable name of the file.  It will not change anything on how to you the homework assignment.  

comlor
Posts: 16
Posted 12:19 Feb 16, 2016 |

If you are having issues reading the file post it here and we can help.    

I found issues with the file as well.  

Not every line is identical.  Some lines have different amounts of data.  There are many that have a phone number added to the end.  There are others that have no address, and then again others that have no zip code.  The core data is separated by commas.  There are break points in the data of a semicolon that separate data within a line

 

Darren76
Posts: 39
Posted 12:20 Feb 16, 2016 |

yes I know, but I can not figure out how to retrieve data from the csv file. I have never done that before and whatever I did is not working out for me :(  Any hints ? I just need the basic idea how to get all the csv file displayed on the web.  

comlor
Posts: 16
Posted 12:32 Feb 16, 2016 |

Ok.  So your problem is accessing the data file from your servlet?  For this you cannot access that data file through a normal URL due to the WEB-INF directory not be addressable.  Below is a link to java-doc that has a resource that will help you with reading in the file.

http://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html - Specifically look at getResourceAsStream()(fixed link.....this was wrong link)

https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html - This will also be helpful as it does two things.  It takes the return type of getResourceAsStream as parameter for the constructor and also has a readline function which is specifically what i was looking for in javadoc when i found this one.

Just read up on those to function and you should be good.  The reason you want to user the first link getResourceAsStream is it is part of the serveletContext.  So this method will resolve URL Paths on the server for you up to your specific web server root.  This means that your file path only has to be /WEB-INF/...whereever your file is....   Using this will allow your program to run no matter if loaded on OS X, Windows, or a Unix/Linux system.

 

Last edited by comlor at 12:47 Feb 16, 2016.
Darren76
Posts: 39
Posted 12:40 Feb 16, 2016 |

ok thanks a lot !  

comlor
Posts: 16
Posted 12:42 Feb 16, 2016 |

no problem.  Also make sure your file is added to your project location just like it would be on cs3 so that it will work when deployed.

comlor
Posts: 16
Posted 12:48 Feb 16, 2016 |

DARREN76.  I just updated the first link in the previous post.  I linked to the wrong location which is much more difficult to read.  Is not points at the location i meant to send you to for ServletContext.