本文整理匯總了Java中java.io.BufferedReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedReader.close方法的具體用法?Java BufferedReader.close怎麽用?Java BufferedReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.BufferedReader
的用法示例。
在下文中一共展示了BufferedReader.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testOpenBufferedStream
import java.io.BufferedReader; //導入方法依賴的package包/類
public void testOpenBufferedStream() throws IOException {
BufferedReader reader = source.openBufferedStream();
assertTrue(source.wasStreamOpened());
assertFalse(source.wasStreamClosed());
StringWriter writer = new StringWriter();
char[] buf = new char[64];
int read;
while ((read = reader.read(buf)) != -1) {
writer.write(buf, 0, read);
}
reader.close();
writer.close();
assertTrue(source.wasStreamClosed());
assertEquals(STRING, writer.toString());
}
示例2: removeData
import java.io.BufferedReader; //導入方法依賴的package包/類
public void removeData(String path, String key) {
createFile(path);
try {
BufferedReader reader = new BufferedReader(new FileReader(new File(KAKAOBOT_HOME, path)));
String line;
StringBuilder result = new StringBuilder();
while((line = reader.readLine()) != null) {
result.append(line);
result.append("\n");
}
JSONObject json = new JSONObject(result.toString() + "");
json.remove(key);
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(KAKAOBOT_HOME, path)));
writer.write(json.toString());
reader.close();
writer.close();
} catch(IOException err) {
err.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
示例3: loadDictionary
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* Load the word frequency list, skipping words that are not in the given white list.
*
* @param whitelist The white list.
* @return A Dictomation dictionary with the word probabilities.
* @throws IOException
* @throws DictionaryBuilderException
*/
public static DictomatonDictionary loadDictionary(Set<String> whitelist) throws IOException, DictionaryBuilderException {
CharSource source = getResource(WORD_FREQUENCIES_FILE);
DictomatonDictionary dictomatonDictionary;
BufferedReader reader = source.openBufferedStream();
try {
if (whitelist == null) {
dictomatonDictionary = DictomatonDictionary.read(reader);
} else {
dictomatonDictionary = DictomatonDictionary.read(reader, whitelist);
}
} finally {
reader.close();
}
return dictomatonDictionary;
}
示例4: respond
import java.io.BufferedReader; //導入方法依賴的package包/類
public void respond() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
String line = "";
while ((line = br.readLine()) != null) {
Chat.log("Receieved: " + line);
// line: Name:ID,Players,Status
ServerStatus.fromString(line);
bw.write("1");
bw.newLine();
bw.flush();
}
bw.close();
br.close();
sock.close();
}
示例5: streamToString
import java.io.BufferedReader; //導入方法依賴的package包/類
public static String streamToString(InputStream is) throws IOException {
String str = "";
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
} finally {
is.close();
}
str = sb.toString();
}
return str;
}
示例6: readStringFromFile
import java.io.BufferedReader; //導入方法依賴的package包/類
private String readStringFromFile(File file) throws IOException {
StringBuffer buff = new StringBuffer();
BufferedReader rdr = new BufferedReader(new FileReader(file));
String line;
try{
while ((line = rdr.readLine()) != null){
buff.append(line + "\n");
}
} finally{
rdr.close();
}
return buff.toString();
}
示例7: execute
import java.io.BufferedReader; //導入方法依賴的package包/類
@Override
public void execute() throws BuildException {
checkParameters();
try {
final BufferedReader in = new BufferedReader(new FileReader(template)); //todo: encoding
try {
final PrintWriter out = new PrintWriter (new FileWriter(destFile)); //todo: encoding
try {
copy (in,out);
} finally {
out.close();
}
} finally {
in.close();
}
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
}
}
示例8: replaceWord
import java.io.BufferedReader; //導入方法依賴的package包/類
private static void replaceWord(String oldWord, String newWord, String file_name) {
try {
File file = new File(file_name);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = "", oldtext = "";
while ((line = reader.readLine()) != null) {
oldtext += line + "\r\n";
}
reader.close();
String newtext = oldtext.replaceAll(oldWord, newWord);
FileWriter writer = new FileWriter(file_name);
writer.write(newtext);
writer.close();
} catch (IOException ioe) {
System.out.println(RED + " [!] Error to generate file! " + ioe.getMessage());
deleteFolder("src/");
System.exit(0);
}
}
示例9: leituraNextId
import java.io.BufferedReader; //導入方法依賴的package包/類
public static void leituraNextId () throws IOException {
String linha = null;
File arquivo = new File("IdPeriodo.dat");
FileReader fr = new FileReader(arquivo);
BufferedReader br = new BufferedReader(fr);
while( br.ready() ){
linha = br.readLine();
}
nextID = Long.parseLong(linha);
br.close();
fr.close();
}
示例10: loadNetwork
import java.io.BufferedReader; //導入方法依賴的package包/類
private void loadNetwork(String networkFile) throws IOException {
int vID = 0, eID = 0;
String line, fromLab, toLab;
float weight;
String[] tokens;
BufferedReader reader = new BufferedReader(new FileReader(networkFile));
while ((line = reader.readLine()) != null) {
line = line.replaceAll("\t", " ");
line = line.replaceAll("\\s+", " ");
tokens = line.split(" ");
fromLab = tokens[0];
toLab = tokens[1];
weight = (float) Double.parseDouble(tokens[2]);
Vertex from = getVertex(vID++, fromLab, true);
Vertex to = getVertex(vID++, toLab, true);
Edge e = new Edge(from, to, weight, false);
e.setId(eID++);
if (fromLab.equalsIgnoreCase(toLab))
System.out.println("WARNING: Loop edge at " + toLab);
network.addEdge(e);
}
reader.close();
}
示例11: inputStreamToString
import java.io.BufferedReader; //導入方法依賴的package包/類
private static String inputStreamToString(InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
return sb.toString();
}
示例12: updateTopScore
import java.io.BufferedReader; //導入方法依賴的package包/類
/**
* 獲取文件中保存的最高分
* 判斷最高分和當前分數的大小,若當前分數大,則替換
*/
public void updateTopScore() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("gamedata/topScore.txt"));
String str = br.readLine();
if(str != null) {
topScore = Integer.parseInt(str);
if(nowScore > topScore) {
br.close();
PrintWriter pw = new PrintWriter(new FileWriter("gamedata/topScore.txt"));
topScore = nowScore;
pw.write("" + nowScore);
pw.close();
}
}
}
示例13: CarregarListaX
import java.io.BufferedReader; //導入方法依賴的package包/類
public void CarregarListaX(String nomelista) throws Exception
{
File file = new File(this.getFilesDir()+"/"+nomelista.trim()+".png");
BufferedReader bf = new BufferedReader(new FileReader(file));
String saida="";
String linha;
while((linha=bf.readLine()) != null)
{
saida = saida+linha;
}
bf.close();
String[] listas=saida.split(";");
routes = new String[(listas.length/2)];
names = new String[(listas.length/2)];
int j=0,k=0;
for(int i=0;i<listas.length;i++)
{
if(i%2==0) {
names[j]=listas[i];
j++;
}else
{
routes[k]=listas[i];
k++;
}
}
BakerAdapter adapter = new BakerAdapter(this,names,routes);
lv.setAdapter(adapter);
}
示例14: readFirstLineFromFile
import java.io.BufferedReader; //導入方法依賴的package包/類
public static String readFirstLineFromFile(File file) {
String line = "";
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
line = reader.readLine();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
示例15: getContentFromUrl
import java.io.BufferedReader; //導入方法依賴的package包/類
private String getContentFromUrl(URL url, String readAfter, String readBefore) throws SchoolException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buffer = new StringBuffer();
String inputLine;
boolean reading = false;
while ((inputLine = reader.readLine()) != null) {
if (reading) {
if (inputLine.contains(readBefore))
break;
buffer.append(inputLine);
} else {
if (inputLine.contains(readAfter))
reading = true;
}
}
reader.close();
return buffer.toString();
} catch (IOException e) {
throw new SchoolException("교육청 서버에 접속하지 못하였습니다.");
}
}