當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedReader.close方法代碼示例

本文整理匯總了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());
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:18,代碼來源:CharSourceTest.java

示例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();
    }
}
 
開發者ID:Su-Yong,項目名稱:NewKakaoBot,代碼行數:29,代碼來源:FileManager.java

示例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;
}
 
開發者ID:calcmen,項目名稱:spellcheck,代碼行數:25,代碼來源:DictionaryUtil.java

示例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();
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:19,代碼來源:MinecraftReceiever.java

示例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;
}
 
開發者ID:inceleb,項目名稱:InstagramManager-Android,代碼行數:25,代碼來源:StringUtil.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:XMLFormatterTest.java

示例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());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:CopyTemplatePageTask.java

示例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);
    }
}
 
開發者ID:tiagorlampert,項目名稱:sAINT,代碼行數:20,代碼來源:sAINT.java

示例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();
}
 
開發者ID:omniplatypus,項目名稱:Projeto-IP2,代碼行數:13,代碼來源:PeriodoDAO.java

示例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();
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:28,代碼來源:TestWeightedKCore.java

示例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();
}
 
開發者ID:jansipke,項目名稱:pvdisplay,代碼行數:11,代碼來源:NetworkUtils.java

示例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();
		}
	}
}
 
開發者ID:brandonbai,項目名稱:game2048_tetris,代碼行數:19,代碼來源:DropPanel.java

示例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);
}
 
開發者ID:olivatooo,項目名稱:ControlBaker,代碼行數:30,代碼來源:TheButtons.java

示例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;
}
 
開發者ID:MindorksOpenSource,項目名稱:CrashReporter,代碼行數:12,代碼來源:FileUtils.java

示例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("교육청 서버에 접속하지 못하였습니다.");
        }
    }
 
開發者ID:JoMingyu,項目名稱:Bobsim-Server,代碼行數:28,代碼來源:School.java


注:本文中的java.io.BufferedReader.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。