Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6.  
  7. public class TraitementFichier
  8. {
  9. public static int compteur = 0;
  10.  
  11. public static void main(String[] args) throws IOException
  12. {
  13. String chaine = lireFichier("Coordonnees.csv");
  14. // System.out.println(compteur);
  15. // System.out.println(chaine);
  16. }
  17.  
  18. public static List<Coordonnee> fromFichier(String nomFichier)
  19. {
  20. String chaine = lireFichier(nomFichier);
  21. String[] stringCoordonnee = chaine.split("\n");
  22.  
  23. List<Coordonnee> listCoord = new ArrayList<Coordonnee>();
  24.  
  25. for (int i = 0; i < compteur; i++)
  26. {
  27. String[] CoordonneeIndividuel = stringCoordonnee.split(";");
  28. Coordonnee coor = new Coordonne(CoordonneeIndividuel[0],
  29. CoordonneeIndividuel[1]);
  30. listCoord.add(coor);
  31. }
  32. return listCoord;
  33.  
  34. }
  35.  
  36. public static String lireFichier(String nomFichier) throws IOException
  37. {
  38. File f = new File(nomFichier);
  39. BufferedReader fR = new BufferedReader(new FileReader(f));
  40. String chaine = "";
  41. String chaine_totale = "";
  42. do
  43. {
  44. compteur++;
  45. chaine = fR.readLine();
  46. if (chaine != null)
  47. {
  48. chaine_totale += chaine + "\n";
  49. }
  50. }
  51. while (chaine != null);
  52. fR.close();
  53. compteur--;
  54. return (chaine_totale);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement