本文整理匯總了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;
}