黑马程序员技术交流社区

标题: 工作区问题 [打印本页]

作者: 邵阳    时间: 2012-9-12 09:54
标题: 工作区问题
本帖最后由 邵阳 于 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, 下载次数: 82)

QQ截图20120912122012.png

作者: 陈俊来    时间: 2012-9-12 10:22
lz能不能把程序先贴出来
作者: 邵阳    时间: 2012-9-12 12:19
陈俊来 发表于 2012-9-12 10:22
lz能不能把程序先贴出来

你看看,已贴出
作者: 陈俊来    时间: 2012-9-12 14:09
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:14
陈俊来 发表于 2012-9-12 14:09
public class MyClassLoader
{
public static void main(String[]args) throws IOException

你是不是没看张孝祥老师讲的java基础提高啊
作者: 陈俊来    时间: 2012-9-12 14:42
张孝祥-7k月薪面试题
张孝祥-java高级视频
张孝祥Java高新技术
张孝祥-java基础教程
java就业面试题宝典.rar


java基础提高?有吗?

作者: 李菁    时间: 2012-9-12 16:55
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);
  }
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2