奇怪,我先用 inputstream 读取了一个 .exe 的文件,然后在原封不动的用 BufferedOutputStream 写出来,但是却不能运行了,这是怎么回事呢。
解决方案 »
- 关于分旬
- 请教,已知primitive Class,如何求得对应的wrapper Class?
- ioexception SocketTimeoutException问题
- 百思不得其解:环境配置好后,java可运行,javac不能运行,注销系统后再登录才可以运行
- 课程设计,都快把我搞麻了...谁能帮忙看一下...MS很简单,但就是搞不明白...
- 错在哪里?
- ActiveMQ的消息接收的问题(使用MessageListener)
- java中字符串操作函数在哪?java中分解字串的函数(如asp中的:split)在哪个类中?
- 在Jbuilder7中编译成功的JApplet,但是在网页中总是显示不对,是不是html文件写的有问题还是……?
- how to do it in java:'A'->65 和 65->'A'
- 求救 java解析html
- java如何处理文本文件中的换行符
如果是,把代码贴出来吧!
InputStream dvdinput = new FileInputStream(file1);
InputStream in = new BufferedInputStream( dvdinput );
System.out.println(in.available());
byte b[] = new byte[ in.available() ];
while( in.read() != -1 ){
in.read();
}
File file2 = new File("D:\\dvd1.avi");
if( !file2.exists() ){
file2.createNewFile();
}
OutputStream outputStream = new FileOutputStream( file2 );
OutputStream outputbuffer = new BufferedOutputStream( outputStream, 512 ); outputbuffer.write(b);
//OutputStream outdvd = new OutputStream();
InputStream dvdinput = new FileInputStream(file1);
InputStream in = new BufferedInputStream( dvdinput );
File file2 = new File("D:\\dvd1.avi");
OutputStream outputStream = new FileOutputStream( file2 );
OutputStream outputbuffer = new BufferedOutputStream( outputStream, 512 );
System.out.println(in.available()); if( !file2.exists() ){
file2.createNewFile();
}
byte b[] = new byte[ in.available() ];
int len= -1;
while( (len=in.read(b)) != -1 ){ // 这里你弄错了!
outputbuffer.write(b,0,len); // 这里读完了,马上写入到新文件
}
outputbuffer.flush();
outputbuffer.close();
in.close();
byte[] buf = new byte[1024];FileInputStream in = new FileInputStream("D:\\dvd.avi");
FileOutputStream out = new FileOutputStream("D:\\dvd1.avi");
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.flush();
out.close();
It'll invoke the flush method automatically.
我是新手,有点小问题.
程序结束时不要写
dvdinput.close();
和
outputStream.close();
吗?