标签:size 处理 ringbuf exce auto final res 语法规则 资源
public static void main(String[] args) { File file = new File("/workspace/test.txt") ; FileInputStream fis = null ; try { fis = new FileInputStream(file) ; StringBuffer buffer = new StringBuffer() ; int c ; while ((c =fis.read()) != -1) { buffer.append((char) c) ; } System.out.print(buffer); } catch (FileNotFoundException e) { // logging // deal exception } catch (IOException e) { // loggin // deal exception } finally { if(fis != null) { try { fis.close(); } catch (IOException e) { // deal exception } } } }
public static void main(String[] args) { File file = new File("/workspace/test.txt") ; try (FileInputStream fis = new FileInputStream(file)) { StringBuffer buffer = new StringBuffer() ; int c ; while ((c =fis.read()) != -1) { buffer.append((char) c) ; } System.out.print(buffer); } catch (FileNotFoundException e) { // logging // deal exception } catch (IOException e) { // loggin // deal exception } }
public interface AutoCloseable { void close() throws Exception; }
标签:size 处理 ringbuf exce auto final res 语法规则 资源
原文地址:http://www.cnblogs.com/sten/p/6013282.html