zoukankan      html  css  js  c++  java
  • CommonsIO 的 IOUtils 的几个简单例子

    //使用JDK的方法
    InputStream in = new URL( "http://www.oschina.net" ).openStream();
    try {
       InputStreamReader inR = new InputStreamReader( in );
       BufferedReader buf = new BufferedReader( inR );
       String line;
       while ( ( line = buf.readLine() ) != null ) {
         System.out.println( line );
       }
    } finally {
       in.close();
    }

    // 使用 IOUtils 的方法
    InputStream in = new URL( "http://www.oschina.net" ).openStream();
    try {
       System.out.println( IOUtils.toString( in ) );
    } finally {
       IOUtils.closeQuietly(in);
    }

    //读取文件所有行
    File file = new File("/commons/io/project.properties");
    List<String> lines = FileUtils.readLines(file, "UTF-8");

    文件路径处理

    String filename = "C:/commons/io/../lang/project.xml";
    String normalized = FilenameUtils.normalize(filename);
    // result is "C:/commons/lang/project.xml"

    磁盘剩余空间

    long freeSpace = FileSystemUtils.freeSpace("C:/");

  • 相关阅读:
    HDU1316 fib+高精度
    HDU1868
    HDU2586 LCA
    HDU1113 字符串处理
    HDU1115 几何+多边形重心
    HDU1124
    HDU1110 几何
    HDU1103
    HDU2670 DP
    linux 下查看机器是cpu是几核的
  • 原文地址:https://www.cnblogs.com/opaljc/p/3058692.html
Copyright © 2011-2022 走看看