代码如下:
public void copyFile(String oldPath, String newPath) throws Exception
{ int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists())
{ //文件存在时  
InputStream inStream = new FileInputStream(oldPath); //读入原文件  
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ((byteread = inStream.read(buffer)) != -1)
{
bytesum += byteread; //字节数  文件大小  
//System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
} }这段代码在本地windows下运行copy大的文件(例如100M以上)检测内存的使用发现只是使用了buffer大小的内容,
但是放到linux系统websphere的jsp/servlet运行用top命令检测发现占用了大量的内存,并且程序执行完毕之后内存占用率仍然高居不下。其实我原本的问题是在websphere上的一个servlet用ftp从另外一台linux服务器读取文件(InputStream)然后把InputStream的字节流out put到客户端给客户下载,但是发现这里的读取/写入操作占用了大量的内存,就跟上面的复制文件情况相似。问题出在In/Out Stream的操作上,但是windows下运行却没有这样的问题。期盼各位鼎立相助,在下感激不尽!