"HttpClient" 를 이용하여 어플리 케이션 실행화일 업데이트 방법
"HttpClient" 를 이용하여 어플리 케이션 실행화일 업데이트 방법
@호출Stack
AppMain(어플리케이션 메인), updateApp(업데이트모듈)
AppMain에서 업데이트 event 수행 => updateApp호출 => AppMain 종료 => updateApp수행 실행파일 다운로드(기존 실행파일 대체됨) => AppMain 실행
AppMain
public void
}
}
updateApp
http 통신/File IO 라이브러리 참조
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.
import org.apache.http.client.
import org.apache.http.impl.client.
public static void
// TODO Auto-
File file = new File("oneDevCenter.exe")
String sPath = file.getAbsolutePath();
HttpClient httpclient = newDefaultHttpClient();
HttpGet httpget = new HttpGet("http://??????/
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
BufferedInputStream bis = newBufferedInputStream(
String filePath =sPath;
BufferedOutputStream bos = newBufferedOutputStream(newF
int inByte;
while ((inByte = bis.read()) != -1 ) {
bos.write(inByte);
}
bis.close();
bos.close();
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
httpget.abort();
throw ex;
} finally {
instream.close();
}
httpclient.
exeCuteAfterJavaStudy();
}
}
AppMain수행 : 파일의 위치를 찾고 수행한다.
public static void
{
Process p;
try {
File file = newFile("oneDevCenter.exe");
String sPath = file.getAbsolutePath();
p = newProcessBuilder(sPath).
System.out.println("Process Done");
} catch (IOException e1) {
e1.printStackTrace();
}
}
Httpclient 는 http 프로토콜을 지원해주는 클라이언트 객체임.
해당 라이브러리를 응용해서 다양하게 구현해 보시기 바랍니다. (예, screen scrapping)
HttpClient library 링크:
Java :
microsoft : http://msdn.microsoft.com/en-