Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class extract {
- JSONObject OOP = null;
- int i=0;
- public extract(JSONObject oop) {
- OOP=oop;
- }
- public boolean cek() throws JSONException{
- boolean exist = OOP.getBoolean("find");
- if(exist == true) {
- OOP = OOP.getJSONObject("media");
- }
- return exist;
- }
- public String photo() throws MalformedURLException, IOException, JSONException {
- i=i+1;
- InputStream foto = new URL(OOP.getString("url")).openStream();
- String path = i + "thepict.jpg";
- File path_t = new File(path);
- path_t.delete();
- System.out.println(foto);
- Files.copy(foto, Paths.get(path));
- path_t = new File(path);
- path_t.deleteOnExit();
- return path;
- }
- public String caption() throws JSONException {
- String capt = OOP.getString("caption");
- System.out.println(capt);
- return capt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment