How to Read xml file in java?

JAVA READ EXCEL CSV FILE?

  • Can someone help me fix my code, I don't know what to use to get to read just the columns. (last names, firstnames, etc.) Read the file specified below into seven arrays, each containing an attribute (ex: last name). The arrays should host up to 50 entries. I need to create an algorithm that outputs all the items in the address book in the following manner: <First name> <Last name>: <e-mail address> Home phone number: <home phone number> Cell phone number: <cell phone number> Resides in <city>, <state> Sample output: Modonna Washington: [email protected] Home phone number: 400-000-1234 Cell phone number: 443-555-5555 Resides in Somewhere, DC FILE addressBook.csv in Microsoft Excel spread sheet Last Names in column A, firstnames in col B, etc. Last Name...... First Name.... E-mail Address.... Home Phone Number.... Cell Phone Number..... City.... State Depp... Johnny..... [email protected]..... 410-000-1234.... 443-555-5555.... Orlando..... FL Jordan Michael [email protected]..... 410-555-6543.... 443-555-9876.... Washington.... DC entry entry [email protected] ####-####_### ###-###-#### Somewhere STATE import java.io.*; import java.util.*; public class AddressBOOKPROGRAM { public static void main(String args[]) { String[] lastName, firstName, email, homePhone, cellPhone, city, state; lastName = new String[51]; firstName = new String[51]; email = new String[51]; homePhone = new String[51]; cellPhone = new String[51]; city = new String[51]; state= new String[51]; System.out.println(" Your Address Book \n File Output:" ); try { Scanner fileIn = new Scanner(new File("C:\\addressBook.csv" ) ) ; fileIn.useDelimiter(","); String temp; while ( fileIn.hasNextLine() ) { temp = fileIn.nextLine(); System.out.println("Line: " + temp); Scanner lineScanner = new Scanner(temp); lineScanner.useDelimiter(","); String tempToken = ""; while ( lineScanner.hasNext() ) { lastName[1] = lineScanner.next(); System.out.println("Token: " + lastName[1]); } } System.out.println(fileIn); } catch (FileNotFoundException e) { System.out.println("Problems reading the file"); e.printStackTrace(); } } }

  • Answer:

David at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.