2015. 1. 25. 17:51
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package URL;

import java.io.InputStream;
import java.net.URL;

public class openStream {
    public static void main(String args[]){
        try {
            URL url=new URL("http://www.google.com");
            InputStream is=url.openStream();
           
            byte buffer[]=new byte[1024];
            int i;
            while((i=is.read(buffer))!=-1){
                System.out.write(buffer,0,i);
            }
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
}

'Java' 카테고리의 다른 글

Runtime : addShutdownHook(Thread hook)  (0) 2015.01.28
Runtime : availableProcessors()  (0) 2015.01.28
URL : openConnection()  (0) 2015.01.25
URL : getAuthority()  (0) 2015.01.25
new URL(String spec) throws MalformedURLException  (0) 2015.01.25
Posted by af334
2015. 1. 25. 17:43
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package URL;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

public class openConnection {
    public static void main(String[] args)throws Exception{
        Date today=new Date();
        long millisecondsPerDay=24*60*60*1000;
       
        URL u=new URL("http://www.google.com");
        URLConnection uc=u.openConnection();
        uc.setIfModifiedSince((new Date(today.getTime() - millisecondsPerDay)).getTime());
        InputStream in=new BufferedInputStream(uc.getInputStream());
        Reader r=new InputStreamReader(in);
        int c;
       
        while((c=r.read())!=-1){
            System.out.println((char)c);
        }
    }
}

'Java' 카테고리의 다른 글

Runtime : availableProcessors()  (0) 2015.01.28
URL : openStream()  (0) 2015.01.25
URL : getAuthority()  (0) 2015.01.25
new URL(String spec) throws MalformedURLException  (0) 2015.01.25
InetAddress : isReacheable(int timeout)  (0) 2015.01.25
Posted by af334
2015. 1. 25. 17:24
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package URL;

import java.net.URL;

public class getAuthority {
    public static void main(String[] args){
        try {
            URL url=new URL("http://www.google.com");
            System.out.println("URL is "+url.toString());
            System.out.println("authority is "+url.getAuthority());
            System.out.println("path is "+url.getPath());
            System.out.println("default post is "+url.getDefaultPort());
            System.out.println("query is "+url.getQuery());
            System.out.println("ref is "+url.getRef());
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
}

'Java' 카테고리의 다른 글

URL : openStream()  (0) 2015.01.25
URL : openConnection()  (0) 2015.01.25
new URL(String spec) throws MalformedURLException  (0) 2015.01.25
InetAddress : isReacheable(int timeout)  (0) 2015.01.25
InetAddress : getLocalHost()  (0) 2015.01.25
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package URL;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class newURL {
    public static void main(String[] argv) throws Exception{
        URLConnection conn=new URL("http://127.0.0.1").openConnection();
        conn.setDoInput(true);
        conn.setRequestProperty("Authorization", "asdfasdf");
        conn.connect();
       
        InputStream in=conn.getInputStream();
        System.out.println(conn);
        System.out.println(in);
    }
}

'Java' 카테고리의 다른 글

URL : openConnection()  (0) 2015.01.25
URL : getAuthority()  (0) 2015.01.25
InetAddress : isReacheable(int timeout)  (0) 2015.01.25
InetAddress : getLocalHost()  (0) 2015.01.25
InetAddress : getHostName()  (0) 2015.01.25
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package InetAddress;

import java.io.IOException;
import java.net.InetAddress;

public class isReachable {
    public static void main(String[] args)throws IOException{
        try {
            int timeout=2000;
            InetAddress[] addresses=InetAddress.getAllByName("www.google.com");
            for(InetAddress address : addresses){
                if(address.isReachable(timeout))
                    System.out.printf("%s is reachable%n",address);
                else
                    System.out.printf("%s could not be contacted%n",address);
            }
        } catch (Exception e) {
                System.out.printf("Unknown host : %s%n","www.google.com");
        }
    }
}


'Java' 카테고리의 다른 글

URL : getAuthority()  (0) 2015.01.25
new URL(String spec) throws MalformedURLException  (0) 2015.01.25
InetAddress : getLocalHost()  (0) 2015.01.25
InetAddress : getHostName()  (0) 2015.01.25
InetAddress : getHostAddress()  (0) 2015.01.25
Posted by af334
2015. 1. 25. 16:56
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package InetAddress;

import java.net.InetAddress;

public class getLocalHost {
    public static void main(String[] args){
        try {
            InetAddress me=InetAddress.getLocalHost();
            String dottedQuad=me.getHostAddress();
            System.out.println("My address is "+dottedQuad);
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
}

'Java' 카테고리의 다른 글

new URL(String spec) throws MalformedURLException  (0) 2015.01.25
InetAddress : isReacheable(int timeout)  (0) 2015.01.25
InetAddress : getHostName()  (0) 2015.01.25
InetAddress : getHostAddress()  (0) 2015.01.25
InetAddress : getCanonicalHostName()  (0) 2015.01.25
Posted by af334
2015. 1. 25. 16:51
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package InetAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class getHostName {
    public static void main(String[] args){
        try {
            InetAddress address=InetAddress.getLocalHost();
            System.out.println("My name is "+address.getHostName());
        } catch (UnknownHostException e) {
                System.out.println("I don't know the name");
        }
    }
}

'Java' 카테고리의 다른 글

InetAddress : isReacheable(int timeout)  (0) 2015.01.25
InetAddress : getLocalHost()  (0) 2015.01.25
InetAddress : getHostAddress()  (0) 2015.01.25
InetAddress : getCanonicalHostName()  (0) 2015.01.25
InetAddress : getByName  (0) 2015.01.25
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package InetAddress;

import java.net.InetAddress;

public class getHostAddress {
    public static void main(String[] args){
        try {
            InetAddress me=InetAddress.getLocalHost();
            String dottedQuad=me.getHostAddress(); 
            System.out.println("My address is : "+dottedQuad);
        } catch (Exception e) {
                e.printStackTrace();
        }
    }   
}

'Java' 카테고리의 다른 글

InetAddress : getLocalHost()  (0) 2015.01.25
InetAddress : getHostName()  (0) 2015.01.25
InetAddress : getCanonicalHostName()  (0) 2015.01.25
InetAddress : getByName  (0) 2015.01.25
InetAddress : getAllByName()  (0) 2015.01.25
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package InetAddress;

import java.net.InetAddress;

public class getCanonicalHostName {
    public static void main(String[] argv)throws Exception{
        InetAddress addr=InetAddress.getByName("127.0.0.1");
        byte[] ipAddr=new byte[] {127,0,0,1};
        addr=InetAddress.getByAddress(ipAddr);
       
        String hostname=addr.getHostName();
        System.out.println(hostname);
       
        String canonicalhostname=addr.getCanonicalHostName();
        System.out.println(canonicalhostname);
    }
}

'Java' 카테고리의 다른 글

InetAddress : getHostName()  (0) 2015.01.25
InetAddress : getHostAddress()  (0) 2015.01.25
InetAddress : getByName  (0) 2015.01.25
InetAddress : getAllByName()  (0) 2015.01.25
FileWriter (File file)  (0) 2015.01.24
Posted by af334
2015. 1. 25. 16:31
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package InetAddress;

import java.net.InetAddress;

public class getByName {
    public static void main(String[] args){
        try {
            InetAddress ia=InetAddress.getByName("localhost");
            System.out.println(ia.getHostName());
        } catch (Exception e) {
                System.err.println(e);
        }
    }
}

'Java' 카테고리의 다른 글

InetAddress : getHostAddress()  (0) 2015.01.25
InetAddress : getCanonicalHostName()  (0) 2015.01.25
InetAddress : getAllByName()  (0) 2015.01.25
FileWriter (File file)  (0) 2015.01.24
Scanner : useDelimeter(String pattern  (0) 2015.01.24
Posted by af334
이전버튼 1 2 3 4 5 ··· 9 이전버튼