📄 inputstreamreaderdemo.java
字号:
/*
* 创建日期 2007-4-13
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author Seveny
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class InputStreamReaderDemo {
public static void main(String[] args) throws IOException {
int b;
InputStreamReader isr = new InputStreamReader(new FileInputStream(
new File("res/mess_big5.txt")), "big5");
String str = "";
try {
System.out.println("The content of text is:");
while ((b = isr.read()) != -1)//顺序读取文件text里的内容并赋值给整型变量b,直到文件结束为止。
{
str += (char)b;
//System.out.print((char) b);
}
isr.close();
isr = null;
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
} catch (Exception e) {
System.out.println(e);
}
System.out.print(str);
OutputStreamWriter isw = new OutputStreamWriter(new FileOutputStream(
"res/mess.txt", true),"UTF-8");
isw.write(str);
isw.close();
isw = null;
System.out.println();
str = getCurrentDate();
System.out.println(str);
}
private static String getCurrentDate() {
SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss", Locale.ENGLISH);
return format.format( new Date() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -