当前位置: 首页>>代码示例>>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;未经允许,请勿转载。