There are several classes for reading and writing files in Java:
Read files
FileReader
InputStreamReader
BufferedReader
FileReader can directly read files, new FileReader (new File ("file. name "))
InputStreamReader must first create the FileInputStream class new InputStreamReader (new FileInputStream (new File ("file. name ")))
The construction parameter of BufferedReader is InputStreamReader new BufferedReader (new InputStreamReader (new FileInputStream (new File ("file. name "))))
Write files
FileWriter
OutputStreamWriter
BufferedWriter
PrintWriter
FileWriter can directly read files, new FileWriter (new File ("file. name "))
OutputStreamWriter must first create the FileOutputStream class new OutputStreamWriter (new FileOutputStream (new File ("file. name ")))
The BufferedWriter constructor is OutputStreamWriternew BufferedWriter (new OutputStreamWriter (new FileOutputStream (new File ("file. name "))))
PrintWriter has many construction parameters. It can be either File or writer.
For more information, see Java API