标签:eclips code 操作 public read ted oid class nts
字符流读取数据不会产生乱码问题Read read= new FileReader(File f);或路径
操作方法:
除了流的选择改变和字节数组变成了字符数组,其他都一样
public class test{
public static void main(String[]args)
{
File f =new File("C:/Users/10853/eclipse-workspace/hell/src/hell/abc");
Reader reader=null;
try {
reader=new FileReader(f);
**char[] flush =new char[1024];**
int len=-1;
try {
while((**len=reader.read(flush))!=-1**)
{//字符数组-->字符串
**String s=new String(flush,0,len);**
System.out.println(s);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=reader)
{
reader.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
}
}
标签:eclips code 操作 public read ted oid class nts
原文地址:https://blog.51cto.com/14437184/2423170