📄 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 + -