62,614
社区成员
发帖
与我相关
我的任务
分享
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader fin = null;
try {
fin = new BufferedReader(new FileReader("a.txt"));
String temp;
while((temp = fin.readLine()) != null)
println(temp);
} finally {
if(fin != null)
fin.close();
}
}
}
if (token==null) return true;
byte[] bytes=token.getBytes(Charset.forName("ISO-8859-1"));
ByteBuffer bf=ByteBuffer.wrap(bytes);
CharBuffer cb=Charset.defaultCharset().decode(bf);
String s=new String(bytes);
System.out.println(s); //ok
System.out.println(cb.toString());//ok
BufferedReader reader = null;
File file = new File("a.txt");
try {
// 视文本文件实际保存编码不同,指定相应的编码格式, 比如:GBK,UTF-8...
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
StringBuilder builder = new StringBuilder();
char[] chars = new char[4096];
int length = 0;
while (0 < (length = reader.read(chars))) {
builder.append(chars, 0, length);
}
return builder.toString();
} finally {
try {
if (reader != null) reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}