请问实现聊天室里互传图片文件有什么好的方法 我本地能通过FilterInputStream把文件写到一个Byte[]里面传过去怎么把Byte[]写到一个新的FILE里呀大家帮帮忙 谢谢啊或者还有什么别的方法 组播聊天室 没服务端 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你贴段代码做参考: InputStream stream = FodderFile.getInputStream(); OutputStream bos = new FileOutputStream(路径); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) bos.write(buffer, 0, bytesRead); bos.close(); stream.close(); FilterInputStream:过滤器输入流。基本字节输入流提供的读取方法只能用来读取字节,但是FilterInputStream可以去读取整数值,double和string,而不仅仅是字节或字符。这个是二进制输出流,向文件里写数据。FileOutputStream output=new FileOutputStream("temp.dat");while(条件){ output.write(..........);}output.close();下面是从文件读取数据FileInputStream input=new FileInputStream("temp.dat");while((value=inoput.read())!=-1){ System.out.print(value+" ");}input.close(); 求教:htmlparser高手 关于Graphics 操作软件 java源码在哪里看的? java很简单的一个问题 怎样往MyEclipse环境下的web项目加载jar包啊? 关于J2EE与JSP的学习? 请教! applet与服务器的连接 在线等待!!JBiulder 7 如何注册?急啊 数据库 和 集合类 java字符串转化数值的问题.
InputStream stream = FodderFile.getInputStream();
OutputStream bos = new FileOutputStream(路径); int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1)
bos.write(buffer, 0, bytesRead);
bos.close();
stream.close();
FileOutputStream output=new FileOutputStream("temp.dat");
while(条件)
{
output.write(..........);
}
output.close();
下面是从文件读取数据
FileInputStream input=new FileInputStream("temp.dat");
while((value=inoput.read())!=-1)
{
System.out.print(value+" ");
}
input.close();