帮我看一下这个!!!!

weidongdong 2003-10-16 03:33:14
import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;


public class Try3
{
public static void main(String[] args)
{
int[] array={1,2,3,4,5,6,7,8,9};
String str="weidongping";
double dbl=100.0;
File aFile=new File("e:/jf/wdp1/file.text");
FileOutputStream file=null;
try{
file=new FileOutputStream(aFile);

}catch(FileNotFoundException e){System.out.println("Usage:FileNotFoundException is catched");}

FileChannel channel=file.getChannel();

ByteBuffer[] bytBuff=new ByteBuffer[3];
bytBuff[0]=bytBuff[0].allocate(8);
bytBuff[1]=bytBuff[1].allocate(8);

bytBuff[0].put(str.getBytes()).flip();
bytBuff[1].putDouble(dbl);
bytBuff[2].allocate(str.length());
bytBuff[2].put(str.getBytes()).flip();

try{

file.write(bytBuff);


}catch(IOException e){System.out.println("write file error"); }

bytBuff[0].clear();
bytBuff[1].clear();
bytBuff[2].clear();

try{
file.close();

}catch(IOException e ){ }

}

}


编译错误提示: write()方法错误,这是怎么回事?????谢谢啦!!!1



...全文
52 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weidongdong 2003-10-16
  • 打赏
  • 举报
回复
好像书上说有个 FileOutputStream.write(ByteBuffers[] buffers) 方法啊,它是将多个通道里的数据一起写入到一个文件中去!!

honkyjiang 2003-10-16
  • 打赏
  • 举报
回复
void FileOutputStream.write(byte[] b) 而不是write (java.nio.ByteBuffer[])
比如file.write(bytBuff[0].array()); 就可以罗 !
DainelLee 2003-10-16
  • 打赏
  • 举报
回复
FileOutputStream.write(byte[])

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧