本文整理汇总了Java中java.io.BufferedReader类的典型用法代码示例。如果您正苦于以下问题:Java BufferedReader类的具体用法?Java BufferedReader怎么用?Java BufferedReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferedReader类属于java.io包,在下文中一共展示了BufferedReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decompress
import java.io.BufferedReader; //导入依赖的package包/类
public static String decompress(byte[] compressed) {
if(compressed==null) return null;
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
try {
GZIPInputStream gis = new GZIPInputStream(bis);
BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
gis.close();
bis.close();
return sb.toString();
}catch (IOException ex){
ex.printStackTrace();
}
return null;
}
示例2: getQueryByRowID
import java.io.BufferedReader; //导入依赖的package包/类
public String getQueryByRowID(int rowID, String pno) {
String filePath = SysConfig.Catalog_Project + "pipeline/" + pno + "/workload.txt";
String query = null;
try (BufferedReader reader = InputFactory.Instance().getReader(filePath)) {
String line = reader.readLine();
String[] splits;
int i = 0;
while ((line = reader.readLine()) != null) {
if (i == rowID) {
splits = line.split("\t");
query = splits[2];
break;
}
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
return query;
}
示例3: runCMD
import java.io.BufferedReader; //导入依赖的package包/类
public void runCMD(String command) throws Exception {
Process p = Runtime.getRuntime().exec("cmd /c cmd.exe /c " + command + " exit");//cmd /c dir 执行完dir命令后关闭窗口。
//runCMD_bat("C:\\1.bat");/调用
//Process p = Runtime.getRuntime().exec("cmd /c start cmd.exe /c " + path + " exit");//显示窗口 打开一个新窗口后执行dir指令(原窗口会关闭)
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String readLine = br.readLine();
while (readLine != null) {
readLine = br.readLine();
System.out.println(readLine);
}
if (br != null) {
br.close();
}
p.destroy();
p = null;
}
示例4: main
import java.io.BufferedReader; //导入依赖的package包/类
public static void main(String ... ags)throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
StringTokenizer tk = new StringTokenizer(in.readLine());
TreeSet<Integer> ts = new TreeSet<>();
for(int i=0;i<n;i++)
{
int val = Integer.parseInt(tk.nextToken());
if(val%2 != 0)
ts.add(i);
}
if(ts.size()%2 != 0)
System.out.println("NO");
else
{
int res = 0;
while(ts.size() != 0)
{
int a = ts.pollFirst();
int b = ts.pollFirst();
res += (b-a-1)*2 + 2;
}
System.out.println(res);
}
}
示例5: getURL
import java.io.BufferedReader; //导入依赖的package包/类
public static String getURL(String surl) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.setProperty("java.net.preferIPv4Addresses", "true");
System.setProperty("java.net.preferIPv6Addresses", "false");
System.setProperty("validated.ipv6", "false");
String fullString = "";
try {
URL url = new URL(surl);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
fullString += line;
}
reader.close();
} catch (Exception ex) {
//showDialog("Verbindungsfehler.",parent);
}
return fullString;
}
示例6: doPostRequest
import java.io.BufferedReader; //导入依赖的package包/类
private void doPostRequest(String destination, String parms) throws IOException {
URL url = new URL(destination);
String response = "";
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(parms);
writer.flush();
writer.close();
os.close();
conn.connect();
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
String line;
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line=br.readLine()) != null) {
response+=line;
}
}
else {
response="";
}
}
示例7: process
import java.io.BufferedReader; //导入依赖的package包/类
private static void process(String urlstring) {
try {
URL url = new URL(urlstring);
System.out.println("Connecting to " + url);
URLConnection connection = url.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
for(String line; (line = in.readLine()) != null; )
if (line.startsWith(MARKER)) {
System.out.println(TAG.matcher(line).replaceAll(""));
}
in.close();
} catch (IOException ioe) {
System.err.println("" + ioe);
}
}
示例8: loadBlacklist
import java.io.BufferedReader; //导入依赖的package包/类
private java.util.HashMap loadBlacklist()
{
java.util.HashMap<String,String> map = new java.util.HashMap<String,String>();
try {
java.io.BufferedReader input = new java.io.BufferedReader( new java.io.FileReader( BLACKLISTFILE ) );
java.lang.String line = "";
while ((line = input.readLine()) != null) {
if (false) {
map.put( line, line );
}
}
input.close();
} catch ( java.io.IOException e ) {
System.out.println( "File is not found" );
}
return map;
}
示例9: loadBlacklist
import java.io.BufferedReader; //导入依赖的package包/类
private java.util.HashMap loadBlacklist()
{
java.util.HashMap<String,String> map = new java.util.HashMap<String,String>();
try {
java.io.BufferedReader input = new java.io.BufferedReader( new java.io.FileReader( BLACKLISTFILE ) );
java.lang.String line = "";
while ((line = input.readLine()) != null) {
if (line.length() > 7) {
map.put( line, line );
}
}
input.close();
} catch ( java.io.IOException e ) {
System.out.println( "File is not found" );
}
return map;
}
示例10: initConfig
import java.io.BufferedReader; //导入依赖的package包/类
private void initConfig() throws IOException {
// generate temporary files
tmpDir = createTempDirectory();
ClassLoader classLoader = EmbeddedCassandraService.class.getClassLoader();
InputStream in = getClass().getResourceAsStream("/cassandra.yaml");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
File tmp = new File(tmpDir.getAbsolutePath() + File.separator + "cassandra.yaml");
// Assert.assertTrue(tmp.createNewFile());
BufferedWriter b = new BufferedWriter(new FileWriter(tmp));
//copy cassandra.yaml; inject absolute paths into cassandra.yaml
String line;
while ((line = reader.readLine()) != null) {
line = line.replace("$PATH", "'" + tmp.getParentFile());
b.write(line + "\n");
b.flush();
}
// Tell cassandra where the configuration files are.
// Use the test configuration file.
System.setProperty(CAS_CONFIG_PROP, tmp.getAbsoluteFile().toURI().toString());
LOG.info("Embedded Cassasndra config generated at [{}]", System.getProperty(CAS_CONFIG_PROP));
}
示例11: main
import java.io.BufferedReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
//напишите тут ваш код
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i = 0;
int count = 0;
double sum = 0;
while (i != -1) {
i = Integer.parseInt(br.readLine());
sum += i;
count++;
}
double avg = (sum+1) / (count-1);
System.out.println(avg);
}
示例12: getNotCommentedLines
import java.io.BufferedReader; //导入依赖的package包/类
private static List<String> getNotCommentedLines(InputStream excludedClassesStream) {
List<String> list = new ArrayList<>();
try(BufferedReader br = new BufferedReader(new InputStreamReader(excludedClassesStream))){
String line;
while ((line = br.readLine()) != null) {
String element = line.trim();
if(! element.startsWith("//") && !element.isEmpty()) {
list.add(element);
}
}
} catch(IOException e) {
throw new RuntimeException(e);
}
return Collections.unmodifiableList(list);
}
示例13: makeContent
import java.io.BufferedReader; //导入依赖的package包/类
/**
* 得到响应对象
*
* @param urlConnection
* @return 响应对象
* @throws IOException
*/
private HttpRespons makeContent(String urlString, HttpURLConnection urlConnection) throws IOException {
HttpRespons httpResponser = new HttpRespons();
try {
InputStream in = urlConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in,
Charset.forName(this.defaultContentEncoding)));
httpResponser.contentCollection = new Vector<String>();
StringBuffer temp = new StringBuffer();
String line = bufferedReader.readLine();
while (line != null) {
httpResponser.contentCollection.add(line);
temp.append(line).append("");
line = bufferedReader.readLine();
}
bufferedReader.close();
String ecod = urlConnection.getContentEncoding();
if (ecod == null)
ecod = this.defaultContentEncoding;
httpResponser.urlString = urlString;
httpResponser.defaultPort = urlConnection.getURL().getDefaultPort();
httpResponser.file = urlConnection.getURL().getFile();
httpResponser.host = urlConnection.getURL().getHost();
httpResponser.path = urlConnection.getURL().getPath();
httpResponser.port = urlConnection.getURL().getPort();
httpResponser.protocol = urlConnection.getURL().getProtocol();
httpResponser.query = urlConnection.getURL().getQuery();
httpResponser.ref = urlConnection.getURL().getRef();
httpResponser.userInfo = urlConnection.getURL().getUserInfo();
httpResponser.content = temp.toString();
httpResponser.contentEncoding = ecod;
httpResponser.code = urlConnection.getResponseCode();
httpResponser.message = urlConnection.getResponseMessage();
httpResponser.contentType = urlConnection.getContentType();
httpResponser.method = urlConnection.getRequestMethod();
httpResponser.connectTimeout = urlConnection.getConnectTimeout();
httpResponser.readTimeout = urlConnection.getReadTimeout();
return httpResponser;
} catch (IOException e) {
throw e;
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
}
示例14: extractEdges
import java.io.BufferedReader; //导入依赖的package包/类
/**
* Reads in all the edges from the BRITE file and adds them to the given graph.
* The required nodes have to present in the given graph.
*
* @param graph graph to add the edges to
* @param reader reader at the position to start
* @throws IOException in case of an I/O error
*/
private static void extractEdges(Graph graph, BufferedReader reader) throws IOException {
String line = reader.readLine();
while (line != null && !line.isEmpty()) {
// split the line into pieces and parse them separately
String[] values = line.split("\t");
if (values.length >= 9) {
int id = Integer.parseInt(values[0]);
int from = Integer.parseInt(values[1]);
int to = Integer.parseInt(values[2]);
float delay = Float.parseFloat(values[4]);
float bandwidth = Float.parseFloat(values[5]);
// get the source and destination nodes from the existing graph
Router fromNode = graph.getRouter(from);
Router toNode = graph.getRouter(to);
if (fromNode != null && toNode != null) {
// create the new edge object
graph.createEdge(id, fromNode, toNode, delay, bandwidth);
}
}
line = reader.readLine();
}
}
示例15: sessionAlreadyImported
import java.io.BufferedReader; //导入依赖的package包/类
public static boolean sessionAlreadyImported(File xmlImportFile, File xmlSessionFile) throws IOException {
BufferedReader br1 = new BufferedReader(new FileReader(xmlSessionFile)); //sessionfile
BufferedReader br2 = new BufferedReader(new FileReader(xmlImportFile)); //desktop import
String s1, s2;
s1 = br1.readLine();
s2 = br2.readLine();
s2 = br2.readLine();
br2.mark(2000);;
while(s1 != null) {
while (s1 != null && s2 != null && s1.equals(s2)) {
s1 = br1.readLine();
s2 = br2.readLine();
if (s2 == null) {
br1.close();
br2.close();
return true;
}
}
br2.reset();
s1 = br1.readLine();
}
br1.close();
br2.close();
return false;
}