[text] json

Viewer

  1. package com.company;
  2.  
  3.  
  4. import java.io.*;
  5. import java.net.URL;
  6. import java.util.Scanner;
  7.  
  8.  
  9.  
  10. public class Main {
  11.     public static void main(String[] args) throws IOException {
  12.  
  13.  
  14.  
  15.         URL url = new URL("https://jsonplaceholder.typicode.com/posts");
  16.  
  17.         Scanner sc = new Scanner(url.openStream());
  18.  
  19.         StringBuffer sb = new StringBuffer();
  20.         while(sc.hasNext()) {
  21.             sb.append(sc.next());
  22.         }
  23.         
  24.         String result = sb.toString();
  25.  
  26.         File file;
  27.  
  28.         String[] strs = result.split("(},)");
  29.  
  30.         for(int j = 1; j<strs.length + 1; j++){
  31.             file = new File("id="+ j + ".json");
  32.             FileWriter myWriter = new FileWriter("id="+ j + ".json");
  33.             myWriter.write(strs[j-1] + "}");
  34.             myWriter.close();
  35.             file.createNewFile();
  36.         }
  37.  
  38.  
  39.     }
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  

Editor

You can edit this paste and save as new:


File Description
  • json
  • Paste Code
  • 24 Feb-2021
  • 885 Bytes
You can Share it: