?? autoinstaller.java
字號:
/**
* 本程序源代碼及其目標程序由Turbo Chen 版權所有.
* 你可以使用,轉載,分發本程序,但必須保留本版權申明內容.
*
* @author Turbo Chen(turbochen@163.com)
* @create date 2004-2-8
*/
package net.turbochen.autoinstaller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
*
*
* 自動安裝器.
*
* @author Turbo Chen(turbochen@163.com)
*/
public class AutoInstaller
{
private InstallConfig installConfig = InstallConfig.getInstance();;
public static void main(String[] args)
{
new AutoInstaller().install();
}
/**
* 開始安裝。
* @author Turbo Chen(turbochen@163.com)
*/
public void install()
{
ClassLoader scl = ClassLoader.getSystemClassLoader();
//讀取要安裝資源的配置信息。
String base = installConfig.getResourceBase();
ResourceCollection resources = InstallConfig.getInstance().getResources();
for ( int i=0;i<resources.size();i++ )
{
Resource res = resources.getResource(i);
File distDir = new File(res.getDistPath());
File distFile = new File(distDir,res.getName());
InputStream srcFile = scl.getResourceAsStream(base+res.getName());
if ( !distFile.exists() && srcFile!=null )
{
extractFile(srcFile, distFile);
}
}
}
/**
* 釋放文件。
* @param origin 原始輸出流。
* @param dest 目標文件。
* @author Turbo Chen(turbochen@163.com)
*/
private static void extractFile(InputStream origin, File dest)
{
try
{
System.out.println("extract to " + dest.getAbsolutePath());
OutputStream os = new FileOutputStream(dest);
byte buf[] = new byte[1024];
int numread = 0;
while ((numread = origin.read(buf)) != -1)
{
os.write(buf, 0, numread);
}
origin.close();
os.close();
}
catch (IOException ioex)
{
ioex.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -