Java host configuration

Asked 2 years ago, Updated 2 years ago, 43 views

I am currently creating an app to save images from the website.

I borrowed the code below, but

java.net.UnknownHostException: sampledomail.com

There was an error and I checked and found out that the host configuration was incomplete. Where and how should I configure it?

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;

public class GetFile {
    public static void main(String args[]){
        newGetFile();
    }
    publicGetFile(){
        try{
            URIuri=new URI("http://sampledomail.com/sample.jpg");
            URL url =uri.toURL();
            URLConnection urlcon=url.openConnection();
            InputStream fileIS=urlcon.getInputStream();
            File saveFile=newFile("a.jpg");
            FileOutputStream fileOS=newFileOutputStream(saveFile);
            intc;
            while(c=fileIS.read())!=-1)fileOS.write(byte)c);
            fileOS.close();
            fileIS.close();

        } catch(URISyntaxExceptione){
            System.err.println(e);
        } catch(MalformedURLExceptione){
            System.err.println(e);
        } catch(IOExceptione){
            System.err.println(e);
        }
    }
}

I'm sure there are many things that I'm a beginner and I can't explain well, but I appreciate your cooperation.

java

2022-09-29 21:21

1 Answers

http://sampledomail.com/ was out of link.I tried a different link and it worked.

This post was edited based on Comments by @Funasy and posted as Community Wiki.

This post was edited based on Comments by @Funasy and posted as Community Wiki.


2022-09-29 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.