java读取txt时出现乱码 - Java / Java SE
就是一个很简单的小程序,要读入txt中的文本。程序如下:
package lesson;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class c {
static String str;
static char[] charnum=new char[1024];
static int i=0;
public static void main(String[] args) {
File aFile = new File("D:/Java/example.txt");
FileInputStream inFile = null;
try {
inFile = new FileInputStream(aFile);
} catch(FileNotFoundException e) {
e.printStackTrace(System.err);
System.exit(1);
}
FileChannel inChannel = inFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate(1024);
try {
while(inChannel.read(buf) != -1) {
str= ((ByteBuffer)(buf.flip())).asCharBuffer().toString();
System.out.println(str);
System.out.println(new String(str.getBytes(),"UTF-8"));
buf.clear();
}
inFile.close();
} catch(IOException
相关问答:
请我用FCK上传文件,在本地的windows机上测试可以,但部署到linux服务器上就上传不了文件,上传文件时一直卡在那里。望各位大虾指点,谢谢!
路过,帮你顶一下。。。。。。。。。。。。。。
上传文件的路径问题, ......
我写了个jsp页面,然后改动了一下,改动的内容就是在jsp页面的js函数里加了个alert()语句,但是我访问这个页面时,死活都是原来页面的内容,我加了很多alert函数还是没改动前的页面内容;tomcat重启了,也重新部署这 ......
id name datetime
1 a 2010-05-13 10:15:00
2 b 2010-05-14 09:10:00
3 d 2010-05-14 10:10:00
如何将距离目前最近的那个记录的name 更新为“x”呢
谢谢咯 啊 呵呵
update table_n ......