| 1 | import com.google.gson.Gson; |
| 2 | |
| 3 | import java.io.BufferedReader; |
| 4 | import java.io.FileInputStream; |
| 5 | import java.io.InputStream; |
| 6 | import java.io.InputStreamReader; |
| 7 | |
| 8 | public class Region { |
| 9 | private String continent; |
| 10 | private String pays; |
| 11 | |
| 12 | public Region() { |
| 13 | } |
| 14 | |
| 15 | @SuppressWarnings("SpellCheckingInspection") |
| 16 | public void lectureOrigine(String continent, String pays) { |
| 17 | Gson gson = new Gson(); |
| 18 | Region r = new Region(); |
| 19 | String contenu = ""; |
| 20 | try { |
| 21 | InputStream flux = new FileInputStream(continent + ".txt"); |
| 22 | InputStreamReader lecture = new InputStreamReader(flux); |
| 23 | BufferedReader buff = new BufferedReader(lecture); |
| 24 | String ligne; |
| 25 | while ((ligne = buff.readLine()) != null) { |
| 26 | contenu += ligne; |
| 27 | } |
| 28 | buff.close(); |
| 29 | } catch (Exception e) { |
| 30 | System.out.println(e.toString()); |
| 31 | } |
| 32 | System.out.println("les information du pays" + pays + " du fichier est : " + contenu); |
| 33 | // maintenant je veux deserialiser |
| 34 | Origin coords3 = gson.fromJson(contenu, Origin.class); |
| 35 | //Coordonnees co = gson.fromJson(json,Coordonnees.class); |
| 36 | System.out.println("Resultat = " + coords3); |
| 37 | } |
| 38 | } |