package org;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.elasticsearch.common.io.FileSystemUtils;
import com.google.common.base.Charsets;
public class FileTest {
public static void main(String[] args) throws Exception {
}
/**
* 2.1版本
* @throws Exception
*/
public static void es2_1() throws Exception {
Path path = Paths.get(new URI(
"http://c.csdnimg.cn/pubfooter/js/tracking.js"));
BufferedReader bufferedReader = FileSystemUtils.newBufferedReader(path
.toUri().toURL(), Charsets.UTF_8);
String s = bufferedReader.readLine();
System.out.println(s);
}
/**
* @return null If no settings set for "settingsPrefix" then return
* <code>null</code>.
* @throws org.elasticsearch.ElasticsearchIllegalArgumentException
* If the Reader can not be instantiated.
* es 1.1版本
*/
public static Reader es1_1(String filePath) throws Exception {
URL fileUrl = new URL(filePath);
Reader reader = null;
try {
reader = new InputStreamReader(fileUrl.openStream(), Charsets.UTF_8);
} catch (IOException ioe) {
}
return reader;
}
}