Back-End - Main Menu/Java 212

Ex16_03 - URLConnection클래스 (1)

package com.kook.ch16Project; import java.net.*; public class Ex16_03 { public static void main(String[] args) { String address = "http://www.codechobo.com/sample/hello.html"; try { URL url = new URL(address); URLConnection conn = url.openConnection(); /* - 응용프로그램과 URL객체와의 통신 링크를 처리하는 최상위 추상 클래스 - http를 위한 통신 링크 클래스는 HttpURLConnection이다. */ System.out.println("conn.toString() : " + conn); } catc..

Ex16_02 - URL(Uniform Resource Location)

package com.kook.ch16Project; import java.net.*; public class Ex16_02 { public static void main(String[] args) throws Exception { URL url = new URL("http://www.javachobo.com:80/sample/" + "hello.html?referer=javachobo#index1"); //URL객체 생성시 URL(String 자원 경로); System.out.println("url.getAuthority() : " + url.getAuthority()); //host명과 포트번호 System.out.println("url.getDefaultPort() : " + url.getDefau..

Ex16_01 - InetAddress클래스

package com.kook.ch16Project; import java.net.*; import java.util.*; public class Ex16_01 { public static void main(String[] args) { //InetAddress는 ip주소를 처리하는 클래스 InetAddress ip = null; InetAddress[] ipArr = null; try { ip = InetAddress.getByName("www.naver.com"); //host명(도메인명)으로 InetAddress객체를 반환한다. System.out.println("getHostName() : " + ip.getHostName()); //host명(도메인명 www.naver.com) System.ou..

Ex15_21 - 역직렬화 (3)

package com.kook.ch15Project; import java.io.*; import java.util.ArrayList; //역직렬화는 직렬화된 문자열을 객체로 변경 public class Ex15_21 { public static void main(String[] args) { try { String fileName = "UserInfo.ser"; FileInputStream fis = new FileInputStream(fileName); BufferedInputStream bis = new BufferedInputStream(fis); ObjectInputStream in = new ObjectInputStream(bis); //객체를 읽을시에는 출력한 순서와 일치시켜야 한다. Use..

Ex15_16 - File (2)

package com.kook.ch15Project; import java.io.*; public class Ex15_16 { public static void main(String[] args) { if(args.length != 1) { System.out.println("인자로 directory 경로를 적어라"); System.exit(0); //프로그램 종료 } File f = new File(args[0]); if(!f.exists() || !f.isDirectory()) { System.out.println("유효하지 않은 디렉토리!"); System.exit(0); } File[] files = f.listFiles(); /* - File[] listFiles()는 file객체의 파일들을 배..

Ex15_15 - File (1)

package com.kook.ch15Project; import java.io.*; public class Ex15_15 { public static void main(String[] args) throws Exception { File f = new File("D:\\test\\Ex15_14.java"); //파일 객체 생성시 파라미터에 경로가 포함된 파일명을 작성해야 한다. String fileName = f.getName(); //파일의 경로르 제외한 파일명만 반환 int pos = fileName.lastIndexOf("."); //파일의 확장자 앞의 .의 색인번호 System.out.println("경로를 제외한 파일명 : " + f.getName()); System.out.println("확..

Ex15_14 - 표준 입출력의 대상변경 (2)

package com.kook.ch15Project; import java.io.*; //표준 입출력 대상 변경 public class Ex15_14 { public static void main(String[] args) { PrintStream ps = null; //보조 스트림 FileOutputStream fos = null; //기반 스트림, 출력 대상을 파일로 지정 try { fos = new FileOutputStream("test1514.txt"); //파일이 없으면 자동으로 생성한다. ps = new PrintStream(fos); //보조 스트림은 기반 스트림과 꼭 같이 만들어야 한다. (자기 자신으로만은 사용불가) System.setOut(ps); //표준 출력을 out을 콘솔이 아닌..