标准输入输出流
public final static InputStream in = null;
public final static PrintStream out = null;
System.in 编译类型:InputStream,运行类型:BufferedInputStream。表示的是标准输入 键盘
System.out 编译类型:PrintStream,运行类型:PrintStream。 表示的是标准输入 显示器
转换流
默认情况下,读取文件是按照UTF-8编码,如果文件按照别的方式编码,就很容易读取到乱码。
包装:其实就是转换。
String filePath = "d:\\a.txt";
InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath,"gbk"));
//注意文件编码格式是啥,就转化成啥格式
BufferedReader br = new BufferedReader(isr); //包装转换流,转换成字符流
String s = br.readLine();
br.close(); //关闭外层流
打印流
只有输出流,没有输入流。
PrintStream out = new PrintStream(System.out);
out.println("hello");
out.write("你好,世界".getBytes());
//print底层调用的是write,所以可以直接调用write进行打印
out.close(); //注意由于out是System.out,这个一结束,sout就不能用了
System.out.println("wowowo"); //无法输出
PrintStream out2 = new PrintStream("d:\\a.txt");
System.setOut(out2);
//修改打印流输出的位置
System.out.println("1111"); //输出到文件当中
public static void main(String[] args) throws IOException {
FileWriter fileWriter = new FileWriter("d:\\a.txt");
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.print("hello,world!!!!!!");
printWriter.flush();
//printWriter.close(); //flush或者close调用一个,才能输入进去
}
Properties
注:键值对不需要有空格,值不需要用引号引起来,值的默认类型是String。
store方法的第二个参数是注释,null表示没有注释。在store方法中,如果没有这个文件就是创建,如果有这个文件就是修改。