JAVA 读取URL
Utility classes
IOUtils contains utility methods dealing with reading, writing and copying. The methods work on InputStream, OutputStream, Reader and Writer.
As an example, consider the task of reading bytes from a URL, and printing them. This would typically done like this:
InputStream in = new URL( "https://commons.apache.org" ).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(); }
With the IOUtils class, that could be done with:
InputStream in = new URL( "https://commons.apache.org" ).openStream(); try { System.out.println( IOUtils.toString( in ) ); } finally { IOUtils.closeQuietly(in); }
IOUtil这个还没搞明白。,就这样吧,我用的上面的