Java (IO) read-write file garbled conversion UTF-8 problem
Read file String? Content?=?"";?//It is recommended to use StringBuffer if the document is very long Try? {FileInputStream FS=NewFileInputStream ("Document Admission")); Inputstreamreader?isr?=?New? InputStreamReader (FIS,? ") UTF-8 "); Bufferedreader?br?=?New? BufferedReader (ISR); String?line?=?NULL; while? ((Line?=?br.readline ())?! =?NULL)? {Content?+=? line; Content?+=?" \ r \ n ";?//? Fill in line break}Catch? (exception?e)? {????????? E.printstacktrace (); } Write file StringBuffer sb=NewStringBuffer ();//File Contents Try? {FileOutputStream fos=NewFileOutputStream ("File path"); OutputStreamWriter OSW=newoutputstreamwriter (FOS, "Utf-8"); Osw.write (SB); Osw.close (); }Catch? (exception?e)? {????????? E.printstacktrace (); }
Java (IO) read-write file garbled conversion UTF-8 problem