add function to write to a file
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package org.example;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
@@ -17,7 +14,6 @@ public class Main {
|
||||
HttpResponse<byte[]> response = makeRequest(uri);
|
||||
decompress(response.body());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static HttpResponse<byte[]> makeRequest(URI uri) throws IOException, InterruptedException {
|
||||
@@ -40,7 +36,23 @@ public class Main {
|
||||
|
||||
String line;
|
||||
while((line = buffer.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
writeToFile(line.substring(1, line.length() -1));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToFile(String line) {
|
||||
File file = new File("test.json");
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.out.println("File exists");
|
||||
}
|
||||
|
||||
try (FileWriter fileWriter = new FileWriter("test.json")) {
|
||||
fileWriter.write(line);
|
||||
System.out.println("succesfully wrote file");
|
||||
} catch (IOException e ){
|
||||
System.out.println("Encountered error");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user