org.matsim.core.utils.io.IOUtils.getAppendingBufferedWriter()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(154)

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

IOUtils.getAppendingBufferedWriter介绍

[英]Tries to open the specified file for writing and returns a BufferedWriter for it. If the filename ends with ".gz", data will be automatically gzip-compressed. The data written will be encoded as UTF-8 (only relevant if you use Umlauts or other characters not used in plain English). If the file already exists, content will not be overwritten, but new content be appended to the file.
[中]尝试打开指定的文件进行写入,并为其返回BufferedWriter。如果文件名以“.gz”结尾,数据将自动进行gzip压缩。写入的数据将被编码为UTF-8(仅当您使用Umlauts或其他非纯英语字符时才相关)。如果文件已存在,则不会覆盖内容,但会将新内容附加到文件中。

代码示例

代码示例来源:origin: matsim-org/matsim

public PrintWriter getWriter(boolean append, String fileName, String header) throws IOException {
    PrintWriter writer;
    if (append) {
      writer = new PrintWriter(IOUtils.getAppendingBufferedWriter(outputPath + "/" + fileName));
    } else {
      writer = new PrintWriter(IOUtils.getBufferedWriter(outputPath + "/" + fileName));
      writer.println(header);
    }
    return writer;
  }
}

代码示例来源:origin: matsim-org/matsim

@Test
public void testGetBufferedWriter_append_gzipped() throws IOException {
  String filename = this.utils.getOutputDirectory() + "test.txt.gz";
  BufferedWriter writer = IOUtils.getAppendingBufferedWriter(filename);
  writer.write("aaa");
  writer.close();
  try {
    IOUtils.getAppendingBufferedWriter(filename);
    Assert.fail("expected exception.");
  } catch (IllegalArgumentException e) {
    log.info("Catched expected exception.", e);
  }
}

代码示例来源:origin: matsim-org/matsim

@Test
public void testGetBufferedWriter_append_lz4() throws IOException {
  String filename = this.utils.getOutputDirectory() + "test.txt.lz4";
  BufferedWriter writer = IOUtils.getAppendingBufferedWriter(filename);
  writer.write("aaa");
  writer.close();
  try {
    IOUtils.getAppendingBufferedWriter(filename);
    Assert.fail("expected exception.");
  } catch (IllegalArgumentException e) {
    log.info("Catched expected exception.", e);
  }
}

代码示例来源:origin: matsim-org/matsim

@Test
public void testGetBufferedWriter_append() throws IOException {
  String filename = this.utils.getOutputDirectory() + "test.txt";
  BufferedWriter writer = IOUtils.getAppendingBufferedWriter(filename);
  writer.write("aaa");
  writer.close();
  BufferedWriter writer2 = IOUtils.getAppendingBufferedWriter(filename);
  writer2.write("bbb");
  writer2.close();
  BufferedReader reader = IOUtils.getBufferedReader(filename);
  String line = reader.readLine();
  Assert.assertEquals("aaabbb", line);
}

代码示例来源:origin: matsim-org/matsim

BufferedWriter bw = IOUtils.getAppendingBufferedWriter(filename);
try{
  for(HullEdge e : this.edges.values()){
bw = IOUtils.getAppendingBufferedWriter(filename);
try{
  for(HullEdge e : this.consideredEdges.values()){

相关文章