黑马程序员技术交流社区
标题:
自定义类加载器时的问题
[打印本页]
作者:
傅宇
时间:
2013-3-13 10:24
标题:
自定义类加载器时的问题
1这几句话详细解释一下?
String srcPath = args[0];
String destDir = args[1];
FileInputStream fis = new FileInputStream(srcPath);
String destFileName = srcPath.substring(srcPath.lastIndexOf('\\')+1);
String destPath = destDir + "\\" + destFileName;
FileOutputStream fos = new FileOutputStream(destPath);
2我已经传入String srcPath = args[0];String destDir = args[1];这两个参数如下:
E:\java0108\workspace\MyEclipse 10\javaenhance\bin\cn\itcast\day2\ClassLoaderAttachment.class itcastlib
我怎么还抛出这个异常java.io.FileNotFoundException呢?
*/
public class MyClassLoader extends ClassLoader{
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String srcPath = args[0];
String destDir = args[1];
FileInputStream fis = new FileInputStream(srcPath);
String destFileName = srcPath.substring(srcPath.lastIndexOf('\\')+1);
String destPath = destDir + "\\" + destFileName;
FileOutputStream fos = new FileOutputStream(destPath);
cypher(fis,fos);
fis.close();
fos.close();
}
private static void cypher(InputStream ips ,OutputStream ops) throws Exception{
int b = -1;
while((b=ips.read())!=-1){
ops.write(b ^ 0xff);
}
}
Exception in thread "main" java.io.FileNotFoundException: E:\java0108\workspace\MyEclipse (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at cn.itcast.day2.MyClassLoader.main(MyClassLoader.java:19)
复制代码
作者:
谢洋
时间:
2013-3-14 01:12
1这几句话详细解释一下?
String srcPath = args[0];
String destDir = args[1];
//建立一个输入流,并联关到E:\java0108\workspace\MyEclipse 10\javaenhance\bin\cn\itcast\day2\ClassLoaderAttachment.class
FileInputStream fis = new FileInputStream(srcPath);
System.out.println(srcPath);//打印下路径,看是否正确
//E:\java0108\workspace\MyEclipse 10\javaenhance\bin\cn\itcast\day2\ClassLoaderAttachment.class 从最一个\符号下标加1的位置起获取子串,
//也就是文件名
:
ClassLoaderAttachment.class
String destFileName = srcPath.substring(srcPath.lastIndexOf('\\')+1);
//获取
ClassLoaderAttachment.class 在工程下的相对路径,作为文件输出目录
String destPath = destDir + "\\" + destFileName;
FileOutputStream fos = new FileOutputStream(destPath);//
2我已经传入String srcPath = args[0];String destDir = args[1];这两个参数如下:
E:\java0108\workspace\MyEclipse 10\javaenhance\bin\cn\itcast\day2\ClassLoaderAttachment.class itcastlib
我怎么还抛出这个异常java.io.FileNotFoundException呢?
*/
public class MyClassLoader extends ClassLoader{
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String srcPath = args[0];
String destDir = args[1];
FileInputStream fis = new FileInputStream(srcPath);
String destFileName = srcPath.substring(srcPath.lastIndexOf('\\')+1);
String destPath = destDir + "\\" + destFileName;
FileOutputStream fos = new FileOutputStream(destPath);
cypher(fis,fos);
fis.close();
fos.close();
}
private static void cypher(InputStream ips ,OutputStream ops) throws Exception{
int b = -1;
while((b=ips.read())!=-1){
ops.write(b ^ 0xff);
}
}
查看一下这个路径E:\java0108\workspace\MyEclipse 10\javaenhance\bin\cn\itcast\day2\有没有这个文件,ClassLoaderAttachment.class
Exception in thread "main" java.io.FileNotFoundException: E:\java0108\workspace\MyEclipse (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at cn.itcast.day2.MyClassLoader.main(MyClassLoader.java:19)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2