A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 邵阳 中级黑马   /  2012-9-12 09:54  /  1501 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 邵阳 于 2012-9-12 19:28 编辑

为什么我打不能生成加密的class文件啊
Exception in thread "main" java.io.FileNotFoundException: C:\Documents (系统找不到指定的文件。)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at cn.itcast.day2.MyClassLoader.main(MyClassLoader.java:16)
我的工作区在C:\Documents and Settings下


package cn.itcast.day2;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class MyClassLoader
{
public static void main(String[]args) throws IOException
{
  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 IOException
{
  int len=0;
  while((len=ips.read())!=-1)
  {
   ops.write(len^0xff);
  }
}
}


发现个问题在C:\Documents and Settings的东西是不能进行输出和输入流的

不知是不是啊

验证如下

D:\java\zuoye\ceshi5>java MyTest C:\Documents and Settings\123.png
Exception in thread "main" java.io.FileNotFoundException: C:\Documents (系统找不
到指定的文件。)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:120)
        at java.io.FileInputStream.<init>(FileInputStream.java:79)
        at MyTest.main(ceshi.java:77)
D:\java\zuoye\ceshi5>java MyTest c:\123.png
D:\java\zuoye\ceshi5>


QQ截图20120912122012.png (14.33 KB, 下载次数: 50)

QQ截图20120912122012.png

6 个回复

倒序浏览
lz能不能把程序先贴出来
回复 使用道具 举报
陈俊来 发表于 2012-9-12 10:22
lz能不能把程序先贴出来

你看看,已贴出
回复 使用道具 举报
public class MyClassLoader
{
public static void main(String[]args) throws IOException
{
  String srcPath=args[0];//args?你是从哪里取得的啊?  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 IOException
{
  int len=0;
  while((len=ips.read())!=-1)
  {
   ops.write(len^0xff);
  }
}
}

//主要问题还是路径问题
如:在本项目下有一个test.txt的文件,可以这样写.
File filePath=new File("");
String pp=filePath.getCanonicalPath();
FileInputStream fis = new FileInputStream(pp+"/test.txt");
回复 使用道具 举报
陈俊来 发表于 2012-9-12 14:09
public class MyClassLoader
{
public static void main(String[]args) throws IOException

你是不是没看张孝祥老师讲的java基础提高啊
回复 使用道具 举报
张孝祥-7k月薪面试题
张孝祥-java高级视频
张孝祥Java高新技术
张孝祥-java基础教程
java就业面试题宝典.rar


java基础提高?有吗?
回复 使用道具 举报
李菁 中级黑马 2012-9-12 16:55:19
7#
public static void main(String[]args) throws IOException
{
  String srcPath=args[0];
  String destDir=args[1];
  FileInputStream fis=new FileInputStream(srcPath);
  String destFileName=srcPath.substring(srcPath.lastIndexOf("\\")+1);  是subString,单词打错了
  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 IOException
{
  int len=0;
  while((len=ips.read())!=-1)
  {
   ops.write(len^0xff);
  }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马