复制图片文件大家来看看问题在哪儿
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
Stream s = new Stream();
s.readjpg();
s.writejpg();
}
}
class Stream {
StringBuffer sb;
Stream() {
sb = new StringBuffer();
}
void writejpg() throws Exception {
File f = new File( "obj.jpg ");
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
DataOutputStream dos = new DataOutputStream(fos);
OutputStreamWriter osw = new OutputStreamWriter(dos);
BufferedWriter bw = new BufferedWriter(osw);
String[] str = sb.toString().split( "\n ");
System.out.println(str.length);
for(int i=0;i <str.length;i++) {
bw.write(str[i]);
bw.newLine();
}
bw.flush();
bw.close();
osw.close();
dos.close();
fos.close();
}
void readjpg() throws Exception {
int i=1;
FileInputStream fis = new FileInputStream( "1.jpg ");
DataInputStream dis = new DataInputStream(fis);
InputStreamReader isd = new InputStreamReader(dis);
BufferedReader br = new BufferedReader(isd);
while(br.readLine()!=null) {
sb.append(br.readLine());
sb.append( "\n ");
System.out.println(i++);
}
br.close();
isd.close();
dis.close();
fis.close();
}
}
运行后为什么目标文件什么也看不到?
------解决方案--------------------你怎么把它当成文本文件在读写哦.只要一个FileInputStream和FileOutputStream就行了.
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
Stream s = new Stream();
s.readjpg( "qd.swf ");
s.writejpg( "b.swf ");
}
}
class Stream {
byte[] b;
Stream() {
}
void writejpg(String filename) throws Exception {
File f = new File(filename);
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
fos.write(b);
fos.close();
}
void readjpg(String filename) throws Exception {
int i = 1;
FileInputStream fis = new FileInputStream(filename);
b=new byte[fis.available()];
fis.read(b);
fis.close();
}
}
为你配合你的思路,我用的byte[]数组读取.