Code example for FileWriter

Methods: close, write

0
        } 
    } 
     
    public static void writeStringToFile( File file, String text ) throws IOException
    { 
        FileWriter out = new FileWriter( file );
        out.write( text );
        out.close();
    } 
     
    public static String readStringFromFile( File file ) throws IOException
    { 
        // From http://stackoverflow.com/a/326440/254218 
        FileInputStream stream = new FileInputStream( file );
        try 
        { 
            FileChannel chan = stream.getChannel();
            MappedByteBuffer buf = chan.map( FileChannel.MapMode.READ_ONLY, 0, chan.size() );
            return Charset.forName( "UTF-8" ).decode( buf ).toString();
        } 
        finally