新手 关于写文件的问题

LW6324879_GMAILCOM 2009-09-23 11:14:36
刚写了一段代码 往文件里写东西,文件的大小增加了,但是打开后没有显示文字,这是怎么会是??
谢谢 解答!!
import java.io.*;
//import java.nio.*;
import java.io.File;
import java.nio.channels.*;
import java.nio.ByteBuffer;
public class myio {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String string="hello java";
String path="E:/java/nihao.txt";
File myFile=new File(path);
myFile.createNewFile();
FileOutputStream fos=new FileOutputStream(myFile);
ByteBuffer bb=ByteBuffer.allocate(1024);
byte[] array=string.getBytes();
bb.put(array);
FileChannel fc=fos.getChannel() ;
fc.write(bb);
}
...全文
74 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,620

社区成员

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

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