FileChannel fc =new
FileOutputStream("data.txt").getChannel();
fc.write(ByteBuffer.wrap("Some text".getBytes()));
fc.close();
fc = new FileInputStream("data.txt").getChannel();
ByteBuffer buff = ByteBuffer.allocate(BSIZE);
fc.read(buff);
buff.flip();
// Doesn't work:
//System.out.println(buff.asCharBuffer());
// Decode using this system's default Charset:
buff.rewind();
String encoding = System.getProperty("file.encoding");//这里的//getProperty后面的属性是怎么回事?是怎么得知这个属性的?
System.out.println("Decoded using " + encoding + ": "
+ Charset.forName(encoding).decode(buff));//还有请解释这一排//的内容
FileOutputStream("data.txt").getChannel();
fc.write(ByteBuffer.wrap("Some text".getBytes()));
fc.close();
fc = new FileInputStream("data.txt").getChannel();
ByteBuffer buff = ByteBuffer.allocate(BSIZE);
fc.read(buff);
buff.flip();
// Doesn't work:
//System.out.println(buff.asCharBuffer());
// Decode using this system's default Charset:
buff.rewind();
String encoding = System.getProperty("file.encoding");//这里的//getProperty后面的属性是怎么回事?是怎么得知这个属性的?
System.out.println("Decoded using " + encoding + ": "
+ Charset.forName(encoding).decode(buff));//还有请解释这一排//的内容
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货