private String readFile ( String path ) throws IOException {
StringBuilder builder = new StringBuilder();
InputStreamReader reader = null;
BufferedReader bfReader = null;
try {
if (path.contains("http://")) {
URL url = new URL(path);
InputStream is = url.openStream();
reader = new InputStreamReader(is,"utf-8");
bfReader = new BufferedReader(reader);
} else {
reader = new InputStreamReader( new FileInputStream( path ), "UTF-8" );
bfReader = new BufferedReader( reader );
}
String tmpContent = null;
while ( ( tmpContent = bfReader.readLine() ) != null ) {
builder.append( tmpContent );
}
bfReader.close();
} catch ( UnsupportedEncodingException e ) {
// 忽略
}
return this.filter( builder.toString() );
}
// 过滤输入字符串, 剔除多行注释以及替换掉反斜杠
private String filter ( String input ) {
return input.replaceAll( "/\\*[\\s\\S]*?\\*/", "" );
}