import java.io.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int b;
byte buffer[]=new byte[2500];
try
{
FileInputStream readfile=new FileInputStream("test.txt");
b=readfile.read(buffer,0,2500);
try
{
String str=new String(buffer,0,b,"Default");
System.out.println(str);
}
catch(UnsupportedEncodingException uio){System.out.println("uio error");}
}
catch(IOException ioe){System.out.println("ioe error");}
}
}
怎么结果却是ioe error?在线等答
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int b;
byte buffer[]=new byte[2500];
try
{
FileInputStream readfile=new FileInputStream("test.txt");
b=readfile.read(buffer,0,2500);
try
{
String str=new String(buffer,0,b,"Default");
System.out.println(str);
}
catch(UnsupportedEncodingException uio){System.out.println("uio error");}
}
catch(IOException ioe){System.out.println("ioe error");}
}
}
怎么结果却是ioe error?在线等答
要和project同一目录哦
如果是和.java源文件在一个目录的话,就得用别的方法了
new FileInputStream("src/test.txt");
试下
Default 该成 GB2312或者GBK或者其他任何可以识别的
没有Default 这个名字的字符集
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int b;
byte buffer[]=new byte[2500];
try
{
FileInputStream readfile=new FileInputStream("test.txt");
b=readfile.read(buffer,0,2500);
try
{
String str=new String(buffer,0,b,"Default");
System.out.println(str);
}
catch(UnsupportedEncodingException uio){System.out.println("uio error");}
}
catch(IOException ioe){ioe.printStackTrace();} //这样就知道是不是找不到文件了,应该是找不到文件的问题}
}