刚写了一段代码 往文件里写东西,文件的大小增加了,但是打开后没有显示文字,这是怎么会是??
谢谢 解答!!
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);
}
谢谢 解答!!
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);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货