One, file read and write
1 Try {2FileInputStream FIS =NewFileInputStream (fileName);3InputStreamReader ISR =NewInputStreamReader (FIS, "UTF-8");4BufferedReader br =NewBufferedReader (ISR);5 String Line;6StringBuilder SB =NewStringBuilder ();7 while(line = Br.readline ())! =NULL)8SB = Sb.append (line+ "\ n");9 br.close ();Ten isr.close (); One fis.close (); A returnsb.tostring (); -}Catch(FileNotFoundException e) { - //TODO auto-generated Catch block the e.printstacktrace (); -}Catch(IOException e) { - //TODO auto-generated Catch block - e.printstacktrace (); +}
1 Try {2FileOutputStream fos =NewFileOutputStream (newFile);3OutputStreamWriter OSW =Newoutputstreamwriter (FOS);4BufferedWriter BW =NewBufferedWriter (OSW);5 bw.write (string);6System.out.println ("File Write succeeded");7 bw.close ();8 osw.close ();9 fos.close ();Ten}Catch(FileNotFoundException e) { One //TODO auto-generated Catch block A e.printstacktrace (); -}Catch(IOException e) { - //TODO auto-generated Catch block the e.printstacktrace (); -}
Java Code Collection