传送图片的问题(ObjectOutputStream) 内存不足运行的时候java -Xmx256M (youclassname) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 程序的工作是:服务器:接收客户端发来的image对象(也就是图片)客户端:先截取屏幕,将它转化为image类型,发发送到服务器端。在运行了一会儿后就出现了out of memories的错误不知道怎么解决,请指点一下。 我觉得好像不是内存不足的问题,而是我的程序占了内存没有释放而引起。因为,刚开始时是可以运行,但是过了半分钟后,就出现了out of memories的错误,程序终止了。请再来指点一下! while (true) { bi=robot.createScreenCapture(new Rectangle(800,600));//????? System.out.println("create Screen Capture is ok!"); image=new ImageIcon((Image)bi); out.writeObject(image); out.flush(); out.close(); image=null; try { Thread.sleep(1500); } catch (Exception ex) { System.err.println("sleep error."); } } 如上所述,socket流应该在使用完后关闭。如你的out,is 简单写了一下,SOCKET连接部分没有写。 public void send() { try { File f = new File("d:\\test.jpg"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f)); BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream()); int ch = bis.read(); while(ch != -1) { bos.write(ch); ch = bis.read(); } bos.flush(); bos.close(); bis.close(); } catch (Exception ex) { ex.printStackTrace(); } } public void receive() { try { File f = new File("d:\\test1.jpg"); if(!f.exists()) { f.createNewFile(); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); BufferedInputStream bis = new BufferedInputStream(socket.getInputStream()); int ch = bis.read(); while(ch != -1) { bos.write(ch); ch = bis.read(); } bos.flush(); bos.close(); bis.close(); } catch (Exception ex) { ex.printStackTrace(); } } 我想要ObjectOutputStream,看来我还是自己搞吧。 j2Se从Access中读取数据时乱码问题.高手解决下 求助:实现一个 spinner 如何在JAVA中获取当前的动态时间 除了Java外,还有那些语言能跨平台 求一个将毫秒转成时分的程序!!! 读取文本时的一个问题 如何jdbc对oracle的大字段进行存取(在线急等) 如果目录不存在,那么这个参数要怎样解决呢?? 有没有其他方法能让JBuilder 8支持更多的字体?像Courier等字体! Java有没有运行速度快的IDE编程环境? JAVA3D问题求救,我快上吊了! 请教,在frame2中如何获得产生它的frame1的组件jTree1?
服务器:接收客户端发来的image对象(也就是图片)客户端:先截取屏幕,将它转化为image类型,发发送到服务器端。在运行了一会儿后就出现了out of memories的错误不知道怎么解决,请指点一下。
因为,刚开始时是可以运行,但是过了半分钟后,就出现了out of memories的错误,程序终止了。请再来指点一下!
bi=robot.createScreenCapture(new Rectangle(800,600));//?????
System.out.println("create Screen Capture is ok!");
image=new ImageIcon((Image)bi);
out.writeObject(image);
out.flush();
out.close();
image=null;
try {
Thread.sleep(1500);
}
catch (Exception ex) {
System.err.println("sleep error.");
}
}
public void send() {
try {
File f = new File("d:\\test.jpg");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
int ch = bis.read();
while(ch != -1) {
bos.write(ch);
ch = bis.read();
}
bos.flush();
bos.close();
bis.close();
} catch (Exception ex) {
ex.printStackTrace();
}
} public void receive() {
try {
File f = new File("d:\\test1.jpg");
if(!f.exists()) {
f.createNewFile();
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
int ch = bis.read();
while(ch != -1) {
bos.write(ch);
ch = bis.read();
}
bos.flush();
bos.close();
bis.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}