gonzalob

Untitled

Jun 10th, 2020
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. package json;
  2.  
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7.  
  8. import org.json.JSONArray;
  9.  
  10. public class JsonUtiles
  11. {
  12.     public static void grabar(JSONArray array) {
  13.         try {
  14.             FileWriter file = new FileWriter("test.json");
  15.             file.write(array.toString());
  16.             file.flush();
  17.             file.close();
  18.  
  19.         } catch (IOException e) {
  20.             e.printStackTrace();
  21.         }
  22.     }
  23.  
  24.     public static String leer()
  25.     {
  26.         String contenido = "";
  27.         try
  28.         {
  29.             contenido = new String(Files.readAllBytes(Paths.get("nuevo.json")));
  30.         }
  31.         catch (IOException e)
  32.         {
  33.             e.printStackTrace();
  34.         }
  35.         return contenido;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment