46_张孝祥_Java基础加强_编写对class文件进行加密的工具类
² 知识细节:有包名的类不能调用无包名的类。
简单的加密程序示例:
/*
参数配置:类名.javaàRun AsàRunConfigurations..-->Arguments
*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class day28ClassLoader {
public static void main(String[] args)throws Exception {
String srcPath = args[0];
String destDir = args[1];
FileInputStream fis = new FileInputStream(srcPath);
String destFileName = srcPath.substring(srcPath.lastIndexOf("\\")+1);
String destFilePath = destDir + "\\" + destFileName;
FileOutputStream fos = new FileOutputStream(destFilePath);
cypher(fis,fos);
}
private static void cypher(InputStream in,OutputStream out)throws Exception{
int b = -1;
while((b=in.read())!=-1){
out.write(b^0xFF);
}
in.close();
out.close();
}
}