最好能把代码全部贴出来,复制粘贴多快啊。我写了个,希望对你有帮助,还有什么问题的话再继续问吧
import java.io.*;
public class FileStream {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//File f= new File("d:\\JAVA/hello.txt");
//File f= new File("D:\\JAVA/lomboz-all-in-one-win32/eclipse/workspace/FileOutputStream1/hello.jpg");
File f= new File("d:\\hello.jpg");
try{
FileOutputStream out=new FileOutputStream(f);
byte buff[]="JAVA".getBytes();
out.write(buff);
out.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
try{
FileInputStream in=new FileInputStream(f);
byte [] buff =new byte[1024];
int len=in.read(buff);
System.out.println(new String(buff,0,len));
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
可以用记事本打开hello.jpg查看内容。
wepoom的代码也不错。
温馨提示:答案为网友推荐,仅供参考