第一个问题:
编码应该是UTF-8的字符编码(Unicode的一种变种),这种编码对常用的ASCII码仍然采用1个字节,而对其他不常用的字符集采用2个字节,这样做可以大大节省资源。
编码应该是UTF-8的字符编码(Unicode的一种变种),这种编码对常用的ASCII码仍然采用1个字节,而对其他不常用的字符集采用2个字节,这样做可以大大节省资源。
解决方案 »
- struts2.18怎么启动不了呢?Unable to load configuration. - action
- hibernate batch-size抓取的问题。
- 有个问题想问问
- 请高手帮忙!——关于struts整合discuz论坛!!
- 关于ibatis的配置文件sqlMapConfig.xml中的Pool.ValidationQuery引发的错误
- jsp问题
- struts actionForm问题
- 100分求 The JasperReports Ultimate Guide
- activation.jar这个包哪儿有下载?
- 请问在EJB中如何保存用户的Session信息.即希望保存类似于JSP中的Session信息.急!!!
- servlet的web.xml配置问题!
- 在CMP中,对于update方法必须我们用代码来实现吗?
try{
byte[] b;
RandomAccessFile rf = new RandomAccessFile("e:\\my.txt","rw");
String str = "ab";
b = str.getBytes();
rf.write(b);
// rf.close();
// rf = new RandomAccessFile("e:\\my.txt","rw");
// 为什么这两行注释掉,就读不道内容,非要先关一次,再初始化一次,才能读
// 回答:因为此时cursor已经到了文件尾,所以你读不道内容,
// 你可以使用seek来定位到起始位置
rf.seek(rf.length() - b.length);
// System.out.print(rf.readChar());
// 为什么这个结果不是a??
// 回答:因为这个char对应两个字节,所以读取的是a+b构成的一个unicode编码
System.out.print((char) rf.readByte()); // 这样就是a }catch(Exception e){
}
如果我写入String str = "中国";
为什么readChar出来,第一个是个?
改成writeChars就可以了 RandomAccessFile rf = new RandomAccessFile("e:\\my.txt","rw");
String str = "china is 中国";
// b = str.getBytes();
rf.writeChars(str);
rf.seek(rf.length() - str.length() * 2);
for(int i = 0; i < str.length(); i ++) {
System.out.print(rf.readChar());
if(i == str.length() - 1)
System.out.println();
}
}catch(Exception e){
}