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

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

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

BufferedWriter.<init>介绍

[英]Constructs a new BufferedWriter, providing out with a buffer of 8192 chars.
[中]构造一个新的BufferedWriter,提供8192个字符的缓冲区。

代码示例

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

try(FileWriter fw = new FileWriter("outfilename", true);
  BufferedWriter bw = new BufferedWriter(fw);
  PrintWriter out = new PrintWriter(bw))
{
  out.println("the text");
  //more code
  out.println("more text");
  //more code
} catch (IOException e) {
  //exception handling left as an exercise for the reader
}

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

try (Writer writer = new BufferedWriter(new OutputStreamWriter(
       new FileOutputStream("filename.txt"), "utf-8"))) {
  writer.write("something");
}

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

/**
 * Returns a buffered writer that writes to a file using the given character set.
 *
 * <p><b>{@link java.nio.file.Path} equivalent:</b> {@link
 * java.nio.file.Files#newBufferedWriter(java.nio.file.Path, Charset,
 * java.nio.file.OpenOption...)}.
 *
 * @param file the file to write to
 * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for
 *     helpful predefined constants
 * @return the buffered writer
 */
public static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException {
 checkNotNull(file);
 checkNotNull(charset);
 return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset));
}

代码示例来源: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: 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

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

代码示例来源:origin: square/spoon

private void writeResultJson() {
 try (Writer result = new BufferedWriter(
   new OutputStreamWriter(new FileOutputStream(new File(output, "result.json")), UTF_8))) {
  gson.toJson(summary, result);
 } catch (IOException e) {
  throw new RuntimeException("Unable to write result.json file.", e);
 }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * @return the report file to save user-facing messages
 */
public static PrintWriter initReportFile() throws Exception {
 File file = new File("./IntegrationReport.txt");
 if (!file.exists()) {
  file.createNewFile();
 }
 FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true);
 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
 PrintWriter reportWriter = new PrintWriter(bufferedWriter);
 // Print the current time to separate integration checker results
 SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
 Date date = new Date();
 reportWriter.printf("%n%n%n***** The integration checker ran at %s. *****%n%n",
   df.format(date));
 return reportWriter;
}

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

try (
  FileWriter fw = new FileWriter(file);
  BufferedWriter bw = new BufferedWriter(fw)
) {
  bw.write(text);
}

代码示例来源: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: apache/incubator-druid

public CsvWriter(final OutputStream outputStream)
{
 this.outputStream = outputStream;
 this.writer = new CSVWriter(new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)));
}

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

public void report(String content) throws ReportException {
  try (Writer writer = new BufferedWriter(new OutputStreamWriter(getOutputStream(), encoding))) {
    writer.write(content);
  } catch (IOException ioe) {
    throw new ReportException(ioe);
  }
}

代码示例来源:origin: org.testng/testng

public static void writeFile(String string, File f) throws IOException {
 f.getParentFile().mkdirs();
 try (FileWriter fw = new FileWriter(f);
   BufferedWriter bw = new BufferedWriter(fw)) {
  bw.write(string);
 }
}

代码示例来源: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: 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: jersey/jersey

public static void generateFile(final String resourceRelativeUrl, final int minimalSize, final String fileName)
    throws IOException {
  LOG.info("Generating file " + fileName);
  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(baseUri).path("generate").path(resourceRelativeUrl);
  final File file = new File(fileName);
  final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
      new FileOutputStream(file), Charset.forName("UTF-8")));
  int actualSize = 0;
  while (actualSize < minimalSize) {
    final String response = target.request().get(String.class);
    writer.write(response + ENTITY_SEPARATOR);
    actualSize += response.length();
  }
  writer.flush();
  writer.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: apache/kylin

private void saveToFile(String fileName, String contents) throws IOException {
    File parentDir = new File(fileName).getParentFile();
    if (!parentDir.exists()) {
      parentDir.mkdirs();
    }

    try (BufferedWriter bufferedWriter = new BufferedWriter(
        new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8))) {
      bufferedWriter.append(contents);
    }
  }
}

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

public static BufferedWriter newBufferedWriter(String path, boolean append) throws FileNotFoundException, UnsupportedEncodingException
{
  return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path, append), "UTF-8"));
}

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

Writer writer = null;

try {
  writer = new BufferedWriter(new OutputStreamWriter(
     new FileOutputStream("filename.txt"), "utf-8"));
  writer.write("Something");
} catch (IOException ex) {
 // report
} finally {
  try {writer.close();} catch (Exception ex) {/*ignore*/}
}

相关文章