//使用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:/");