Java 中的文件读写有如下几个类
读文件类
FileReader
InputStreamReader
BufferedReader
FileReader可以直接读文件, new FileReader(new File("file.name"))
InputStreamReader 得先创建FileInputStream 类 new InputStreamReader(new FileInputStream(new File("file.name")))
BufferedReader 的构造参数是InputStreamReader new BufferedReader(new InputStreamReader(new FileInputStream(new File("file.name"))))
写文件
FileWriter
OutputStreamWriter
BufferedWriter
PrintWriter
FileWriter可以直接读文件, new FileWriter(new File("file.name"))
OutputStreamWriter得先创建FileOutputStream 类 new OutputStreamWriter(new FileOutputStream(new File("file.name")))
BufferedWriter的构造参数是OutputStreamWriternew BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("file.name"))))
PrintWriter的构造参数很多。可以直接是File,也可以是writer
具体怎么用,还请参照Java API