[java/net] 인터넷 URL 이미지 주소를 이용하여 이미지를 내 pc에 copy하기 public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); System.out.println("웹에서 가져올 이미지 주소를 입력하세요"); String url =sc.next(); URL u = new URL(url); //USL 메소드/사용자 입력값 선언 URLConnection con = u.openConnection(); //URL 메소드 생성 int imgsize = con.getContentLength(); // 이미지 크기 확인 System.out.println(imgsize); //이미지 크기 출력 String imgtype=con.getContentType(); //이미지 TYPE .. 2022. 6. 27. [java/net] 인터넷 URL 이미지 주소로 파일 크기/형태 확인 URLConnection/openConnection 인터넷 URL 이미지 주소로 파일 크기/형태 확인 및 내 PC에 저장하는 법 public class net2 { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); System.out.println("웹에서 가져올 이미지 주소를 입력하세요"); String url =sc.next(); URL u = new URL(url); //USL 메소드/사용자 입력값 선언 URLConnection con = u.openConnection(); //URL 메소드 생성 int imgsize = con.getContentLength(); // 이미지 크기 확인 System.out.println(imgsize.. 2022. 6. 27. [java/net] InetAddress ,getByName,getAllByName,getHostAddress 사용 예시 InetAddress : IPnetworkAddress getByName : 접속할 도메인명 getAllByName :도메인 IP정보 확인 (!배열!) getHostAddress:IP주소(숫자)를 문자열로 반환 public static void main(String[] args) throws Exception { //server에 연결 하기위해 //InetAddress : IPnetworkAddress //getByName : 접속할 도메인 주소명을 말합니다. InetAddress ia = InetAddress.getByName("localhost"); //!!자기 기본 정보 확인!! System.out.println(ia); //System.out.println(ia.getHostName()); // .. 2022. 6. 27. [java/이미지 파일 용량제한] InputStream, byte, available() public static void main(String[] args) throws IOException{ String file="C:\\java5\\File_Strame\\src\\img2.jpg"; InputStream is = new FileInputStream(file); byte filesize[] = new byte[is.available()]; // 1. 전체 읽고 용량확인 int total = is.read(filesize); //2. 용량 값 선언 if(total > 92160) { //용량 제한 System.out.println("이미지 제한 용량은 90kb까지 입니다."); } else { System.out.println("정상적으로 등록되었습니다."); } } 결과값 2022. 6. 27. [java/File] image File road 정리 이미지 파일은 FileInputStream 을 이용해서 로드해야한다. InputStream is = new FileInputStream(""); 가능OK InputStream is = new FileImageInputStream(""); 가능OK //자바 7이전에 많이 사용 FileInputStream fs = new FileInputStream(""); 가능OK IOException 위치는 2가지 가능 main에 써줘도되고 catch에 써줘도된다. 또 catch를 2개 추가하여 Exception추가 가능 1. 방법 public static void main(String[] args) throws IOException{ 2. 방법 public static void main(String[] args) tr.. 2022. 6. 27. 이전 1 ··· 52 53 54 55 56 57 다음