从文件URL获取BufferedReader
/** from * n o w j a v a . c o m **/ //package com.nowjava; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Main { public static void main(String[] argv) throws Exception { String fileUrl = "nowjava.com"; String encoding = "nowjava.com"; System.out.println(getReader(fileUrl, encoding)); } public static BufferedReader getReader(String fileUrl, String encoding)/**from 时代Java - N o w J a v a . c o m**/ throws IOException { InputStreamReader reader; try { if (encoding == null) { reader = new FileReader(fileUrl); } else { reader = new InputStreamReader( new FileInputStream(fileUrl), encoding); } } catch (FileNotFoundException e) { // try a real URL instead URL url = new URL(fileUrl); if (encoding == null) { reader =