Guest User

Untitled

a guest
Feb 1st, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class CSVRead
  5. {
  6. public static void main(String[] args)
  7. throws Exception
  8. {
  9.  
  10. BufferedReader CSVFile =
  11. new BufferedReader(new FileReader("test123.csv"));
  12. int invalidvar = 1;
  13.  
  14. Scanner input = new Scanner(System.in);
  15. System.out.println("Enter your email");
  16. String email =input.nextLine();
  17.  
  18. System.out.println("Enter your password");
  19. String password =input.nextLine();
  20.  
  21. String dataRow = CSVFile.readLine(); // Read first line.
  22. // The while checks to see if the data is null. If
  23. // it is, we've hit the end of the file. If not,
  24. // process the data.
  25.  
  26. while (dataRow != null)
  27. {
  28. String[] dataArray = dataRow.split("\\t");
  29.  
  30.  
  31. if ((dataArray[0].equals(email))
  32. &&(dataArray[1].equals(password)))
  33. {
  34. System.out.println("You email is " +dataArray[0]+".");
  35. System.out.println("You password is " +dataArray[1]+".");
  36. System.out.println("You first name is " +dataArray[2]+".");
  37. System.out.println("You second name is " +dataArray[3]+".");
  38. System.out.println("You street name is " +dataArray[4]+".");
  39. System.out.println("You city name is " +dataArray[5]+".");
  40. System.out.println("You postcode is " +dataArray[6]+".");
  41. }
  42.  
  43. else
  44. {
  45. System.out.println("Error");
  46. break;
  47. }
  48.  
  49.  
  50. dataRow = CSVFile.readLine();
  51. }
  52. // Close the file once all data has been read.
  53. CSVFile.close();
  54.  
  55. // End the printout with a blank line.
  56. System.out.println();
  57.  
  58. } //main()
  59. } // CSVRead
Advertisement
Add Comment
Please, Sign In to add comment