java.io.BufferedWriter.close()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(270)

本文整理了Java中java.io.BufferedWriter.close()方法的一些代码示例,展示了BufferedWriter.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedWriter.close()方法的具体详情如下:
包路径:java.io.BufferedWriter
类名称:BufferedWriter
方法名:close

BufferedWriter.close介绍

[英]Closes this writer. The contents of the buffer are flushed, the target writer is closed, and the buffer is released. Only the first invocation of close has any effect.
[中]关闭此作者。刷新缓冲区的内容,关闭目标写入程序,释放缓冲区。只有第一次调用close才有效。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

public static void print(String[][] cols) throws Exception {
 BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename));
 for (String[] col : cols) {
  if (col.length >= 2) {
   out.write(col[0] + "\t" + col[1] + "\n");
  } else {
   out.write("\n");
  }
 }
 out.flush();
 out.close();
}

代码示例来源:origin: stackoverflow.com

PrintWriter out = null;
try {
  fw = new FileWriter("myfile.txt", true);
  bw = new BufferedWriter(fw);
  out = new PrintWriter(bw);
  out.println("the text");
      bw.close();
  } catch (IOException e) {

代码示例来源:origin: androidannotations/androidannotations

private static boolean writeValue(Socket client, String value) {
  boolean result;
  BufferedWriter out = null;
  try {
    OutputStream clientStream = client.getOutputStream();
    out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
    out.write(value);
    out.write("\n");
    out.flush();
    result = true;
  } catch (Exception e) {
    result = false;
  } finally {
    if (out != null) {
      try {
        out.close();
      } catch (IOException e) {
        result = false;
      }
    }
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8"));
writer.write(content);
writer.close();
wr.close();

代码示例来源:origin: FudanNLP/fnlp

/**
 * 将字符串写到文件
 * @param path
 * @param str
 * @throws IOException
 */
public static void write(String path, String str) throws IOException {
  BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
      path), "utf8"));
  out.append(str);
  out.close();		
}
public static void write(String path, Serializable o) {

代码示例来源:origin: pxb1988/dex2jar

public static String toStd(DexClassNode expected) throws IOException {
    StringWriter stringWriter = new StringWriter();
    BufferedWriter bufferedWriter = new BufferedWriter(stringWriter);
    BaksmaliDumpOut out = new BaksmaliDumpOut(bufferedWriter);
    final BaksmaliDumper bs = new BaksmaliDumper(true, false);
    bs.baksmaliClass(expected, out);
    bufferedWriter.close();
    return stringWriter.toString();
  }
}

代码示例来源:origin: hankcs/HanLP

/**
 * 导出特征模板
 *
 * @param templatePath
 * @throws IOException
 */
public void dumpTemplate(String templatePath) throws IOException
{
  BufferedWriter bw = IOUtil.newBufferedWriter(templatePath);
  String template = getTemplate();
  bw.write(template);
  bw.close();
}

代码示例来源:origin: apache/storm

public static void writeToFile(File file, Set<String> content) throws IOException {
  FileWriter fw = new FileWriter(file, false);
  BufferedWriter bw = new BufferedWriter(fw);
  Iterator<String> iter = content.iterator();
  while (iter.hasNext()) {
    bw.write(iter.next());
    bw.write(System.lineSeparator());
  }
  bw.close();
}

代码示例来源:origin: FudanNLP/fnlp

public void biList2File(String output) throws IOException {
  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
  for (ArrayList<String> list : clusterResult) {
    for (String s : list) {
      bw.write(s + " ");
    }
    bw.write("\n");
  }
  bw.close();
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {
  String nodeValue = "i am mostafa";

  // you want to output to file
  // BufferedWriter writer = new BufferedWriter(new FileWriter(file3, true));
  // but let's print to console while debugging
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

  String[] words = nodeValue.split(" ");
  for (String word: words) {
    writer.write(word);
    writer.newLine();
  }
  writer.close();
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void produceTrees(String filename, int numTrees) {
 try {
  FileWriter fout = new FileWriter(filename);
  BufferedWriter bout = new BufferedWriter(fout);
  PrintWriter pout = new PrintWriter(bout);
  produceTrees(pout, numTrees);
  pout.close();
  bout.close();
  fout.close();
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void translateFile(String input, String output) {
 try {
  FileInputStream fis = new FileInputStream(input);
  InputStreamReader isr = new InputStreamReader(fis, "utf-8");
  BufferedReader br = new BufferedReader(isr);
  FileOutputStream fos = new FileOutputStream(output);
  OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
  BufferedWriter bw = new BufferedWriter(osw);
  translateLines(br, bw);
  bw.close();
  osw.close();
  fos.close();
  br.close();
  isr.close();
  fis.close();
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
}

代码示例来源:origin: google/guava

public void testNewWriter() throws IOException {
 File temp = createTempFile();
 try {
  Files.newWriter(temp, null);
  fail("expected exception");
 } catch (NullPointerException expected) {
 }
 try {
  Files.newWriter(null, Charsets.UTF_8);
  fail("expected exception");
 } catch (NullPointerException expected) {
 }
 BufferedWriter w = Files.newWriter(temp, Charsets.UTF_8);
 try {
  w.write(I18N);
 } finally {
  w.close();
 }
 File i18nFile = getTestFile("i18n.txt");
 assertTrue(Files.equal(i18nFile, temp));
}

代码示例来源:origin: apache/hive

static void writeFile(File outputFile, String str) throws IOException {
 BufferedWriter w = new BufferedWriter(new FileWriter(outputFile));
 w.write(str);
 w.close();
}

代码示例来源:origin: hankcs/HanLP

@Override
  public boolean saveTxtTo(String path)
  {
    try
    {
      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path)));
      bw.write(toString());
      bw.close();
    }
    catch (Exception e)
    {
      logger.warning("在保存转移矩阵词典到" + path + "时发生异常" + e);
      return false;
    }
    return true;
  }
}

代码示例来源:origin: stackoverflow.com

URL url = new URL("http://yoururl.com");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);

Uri.Builder builder = new Uri.Builder()
    .appendQueryParameter("firstParam", paramValue1)
    .appendQueryParameter("secondParam", paramValue2)
    .appendQueryParameter("thirdParam", paramValue3);
String query = builder.build().getEncodedQuery();

OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
      new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();

conn.connect();

代码示例来源:origin: stanfordnlp/CoreNLP

static public void writeColumnOutput(String outFile, boolean batchProcessSents, Map<String, Class<? extends TypesafeMap.Key<String>>> answerclasses) throws IOException, ClassNotFoundException {
 BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
 ConstantsAndVariables.DataSentsIterator sentsIter = new ConstantsAndVariables.DataSentsIterator(batchProcessSents);
 while(sentsIter.hasNext()){
  Pair<Map<String, DataInstance>, File> sentsf = sentsIter.next();
  writeColumnOutputSents(sentsf.first(), writer, answerclasses);
 }
 writer.close();
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static void dumpMatrix(String filename, SimpleMatrix matrix) throws IOException {
 String matrixString = matrix.toString();
 int newLine = matrixString.indexOf("\n");
 if (newLine >= 0) {
  matrixString = matrixString.substring(newLine + 1);
 }
 FileWriter fout = new FileWriter(filename);
 BufferedWriter bout = new BufferedWriter(fout);
 bout.write(matrixString);
 bout.close();
 fout.close();
}

代码示例来源:origin: androidannotations/androidannotations

private boolean listWindows(Socket client) {
  boolean result = true;
  BufferedWriter out = null;
  try {
    mWindowsLock.readLock().lock();
    OutputStream clientStream = client.getOutputStream();
    out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
    for (Entry<View, String> entry : mWindows.entrySet()) {
      out.write(Integer.toHexString(System.identityHashCode(entry.getKey())));
      out.write(' ');
      out.append(entry.getValue());
      out.write('\n');
    }
    out.write("DONE.\n");
    out.flush();
  } catch (Exception e) {
    result = false;
  } finally {
    mWindowsLock.readLock().unlock();
    if (out != null) {
      try {
        out.close();
      } catch (IOException e) {
        result = false;
      }
    }
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

BufferedWriter writer = new BufferedWriter(
    new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.close();
os.close();
int responseCode=conn.getResponseCode();

相关文章