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

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

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

BufferedWriter.newLine介绍

[英]Writes a newline to this writer. On Android, this is "\n". The target writer may or may not be flushed when a newline is written.
[中]给这位作家写一行新词。在Android上,这是“\n”。写换行时,目标写入程序可能会刷新,也可能不会刷新。

代码示例

代码示例来源:origin: oblac/jodd

private void writeBaseProperty(final BufferedWriter bw, final String key, final String value)
      throws IOException {
    bw.write(key + '=' + value);
    bw.newLine();
  }
}

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

public static void writeFileByLine(String filePath, List<String> linesToWrite) throws IOException {
  LOG.debug("For CGroups - writing {} to {} ", linesToWrite, filePath);
  File file = new File(filePath);
  if (!file.exists()) {
    LOG.error("{} does not exist", filePath);
    return;
  }
  try (FileWriter writer = new FileWriter(file, true);
     BufferedWriter bw = new BufferedWriter(writer)) {
    for (String string : linesToWrite) {
      bw.write(string);
      bw.newLine();
      bw.flush();
    }
  }
}

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

/**
 * 将Map写到文件
 * @param map
 * @throws IOException 
 */
public static void write(Map map,String file) throws IOException {
  BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(
      new FileOutputStream(file), "UTF-8"));
  Iterator iterator = map.entrySet().iterator();
  while (iterator.hasNext()) {
    Map.Entry entry = (Map.Entry)iterator.next();
    String key = entry.getKey().toString();
    String v = entry.getValue().toString();
    bout.append(key);
    bout.append("\t");
    bout.append(v);
    bout.newLine();
  }
  bout.close();
}

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

String encoding = "UTF-8";
int maxlines = 100;
BufferedReader reader = null;
BufferedWriter writer = null;

try {
  reader = new BufferedReader(new InputStreamReader(new FileInputStream("/bigfile.txt"), encoding));
  int count = 0;
  for (String line; (line = reader.readLine()) != null;) {
    if (count++ % maxlines == 0) {
      close(writer);
      writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("/smallfile" + (count / maxlines) + ".txt"), encoding));
    }
    writer.write(line);
    writer.newLine();
  }
} finally {
  close(writer);
  close(reader);
}

代码示例来源:origin: org.codehaus.groovy/groovy

public Writer writeTo(Writer out) throws IOException {
  BufferedWriter bw = new BufferedWriter(out);
  String line;
  BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
  while ((line = br.readLine()) != null) {
    if (bcw.call(line)) {
      bw.write(line);
      bw.newLine();
    }
  }
  bw.flush();
  return out;
}

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

/**
 * 标准化评测分词器
 *
 * @param segment    分词器
 * @param outputPath 分词预测输出文件
 * @param goldFile   测试集segmented file
 * @param dictPath   训练集单词列表
 * @return 一个储存准确率的结构
 * @throws IOException
 */
public static CWSEvaluator.Result evaluate(Segment segment, String outputPath, String goldFile, String dictPath) throws IOException
{
  IOUtil.LineIterator lineIterator = new IOUtil.LineIterator(goldFile);
  BufferedWriter bw = IOUtil.newBufferedWriter(outputPath);
  for (String line : lineIterator)
  {
    List<Term> termList = segment.seg(line.replaceAll("\\s+", "")); // 一些testFile与goldFile根本不匹配,比如MSR的testFile有些行缺少单词,所以用goldFile去掉空格代替
    int i = 0;
    for (Term term : termList)
    {
      bw.write(term.word);
      if (++i != termList.size())
        bw.write("  ");
    }
    bw.newLine();
  }
  bw.close();
  CWSEvaluator.Result result = CWSEvaluator.evaluate(goldFile, outputPath, dictPath);
  return result;
}

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

public void appendLog(String text)
{       
  File logFile = new File("sdcard/log.file");
  if (!logFile.exists())
  {
   try
   {
     logFile.createNewFile();
   } 
   catch (IOException e)
   {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
  }
  try
  {
   //BufferedWriter for performance, true to set append to file flag
   BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
   buf.append(text);
   buf.newLine();
   buf.close();
  }
  catch (IOException e)
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
}

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

BufferedWriter bufOut = new BufferedWriter( new OutputStreamWriter( out ) );
while ( true ) {
  try {
    String msg = bufIn.readLine();
    System.out.println( "Received: " + msg );
    bufOut.write( msg );
    bufOut.newLine(); //HERE!!!!!!
    bufOut.flush();
  } catch ( IOException e ) {

代码示例来源:origin: oblac/jodd

private void writeProfileProperty(final BufferedWriter bw, final String profileName,
                 final String key, final String value)
    throws IOException {
  bw.write(key + '<' + profileName + '>' + '=' + value);
  bw.newLine();
}

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

private void updateIndex(long txId) {
  LOG.debug("Starting index update.");
  final Path tmpPath = tmpFilePath(indexFilePath.toString());
  try (FSDataOutputStream out = this.options.fs.create(tmpPath, true);
     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) {
    TxnRecord txnRecord = new TxnRecord(txId, options.currentFile.toString(), this.options.getCurrentOffset());
    bw.write(txnRecord.toString());
    bw.newLine();
    bw.flush();
    out.close();       /* In non error scenarios, for the Azure Data Lake Store File System (adl://),
              the output stream must be closed before the file associated with it is deleted.
              For ADLFS deleting the file also removes any handles to the file, hence out.close() will fail. */
    /*
     * Delete the current index file and rename the tmp file to atomically
     * replace the index file. Orphan .tmp files are handled in getTxnRecord.
     */
    options.fs.delete(this.indexFilePath, false);
    options.fs.rename(tmpPath, this.indexFilePath);
    lastSeenTxn = txnRecord;
    LOG.debug("updateIndex updated lastSeenTxn to [{}]", this.lastSeenTxn);
  } catch (IOException e) {
    LOG.warn("Begin commit failed due to IOException. Failing batch", e);
    throw new FailedException(e);
  }
}

代码示例来源:origin: apache/incubator-druid

for (int j = 0; j < 20; j++) {
  double value = rand.nextDouble();
  buildData.write("2016010101");
  buildData.write('\t');
  buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data
  buildData.write('\t');
  buildData.write(Integer.toString(product)); // product dimension
  buildData.write('\t');
  buildData.write(Double.toString(value));
  buildData.newLine();
  sketch.update(value);
  sequenceNumber++;
 sketchData.write('\t');
 sketchData.write(StringUtils.encodeBase64String(sketch.toByteArray(true)));
 sketchData.newLine();
buildData.close();
sketchData.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: stackoverflow.com

try {
  Socket s = new Socket("localhost", 60010);
  BufferedWriter out = new BufferedWriter(
      new OutputStreamWriter(s.getOutputStream()));
    out.write("Hello World!");
    out.newLine();
    out.flush();

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

private static void writePoint(double[] coordinates, StringBuilder buffer, BufferedWriter out) throws IOException {
  buffer.setLength(0);
  // write coordinates
  for (int j = 0; j < coordinates.length; j++) {
    buffer.append(FORMAT.format(coordinates[j]));
    if (j < coordinates.length - 1) {
      buffer.append(DELIMITER);
    }
  }
  out.write(buffer.toString());
  out.newLine();
}

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

public void stripDuplicatesFromFile(String filename) {
  BufferedReader reader = new BufferedReader(new FileReader(filename));
  Set<String> lines = new HashSet<String>(10000); // maybe should be bigger
  String line;
  while ((line = reader.readLine()) != null) {
    lines.add(line);
  }
  reader.close();
  BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
  for (String unique : lines) {
    writer.write(unique);
    writer.newLine();
  }
  writer.close();
}

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

private static void writePoint(double[] data, StringBuilder buffer, BufferedWriter out) throws IOException {
    buffer.setLength(0);

    // write coordinates
    for (int j = 0; j < data.length; j++) {
      buffer.append(FORMAT.format(data[j]));
      if (j < data.length - 1) {
        buffer.append(DELIMITER);
      }
    }

    out.write(buffer.toString());
    out.newLine();
  }
}

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

public static void storeClassesAndMethods(List<ClassAndMethods> cams, File file)
  throws IOException {
 FileWriter fw = new FileWriter(file);
 BufferedWriter out = new BufferedWriter(fw);
 for (ClassAndMethods entry : cams) {
  out.append(ClassAndMethodDetails.convertForStoring(entry));
  out.newLine();
 }
 out.flush();
 out.close();
}

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

@Override
protected void convertCorpus(Sentence sentence, BufferedWriter bw) throws IOException
{
  List<String[]> collector = Utility.convertSentenceToNER(sentence, tagSet);
  for (String[] tuple : collector)
  {
    bw.write(tuple[0]);
    bw.write('\t');
    bw.write(tuple[1]);
    bw.write('\t');
    bw.write(tuple[2]);
    bw.newLine();
  }
}

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

public static void storeClassesAndVariables(List<ClassAndVariables> cams, File file)
   throws IOException {
  FileWriter fw = new FileWriter(file);
  BufferedWriter out = new BufferedWriter(fw);
  for (ClassAndVariables entry : cams) {
   out.append(ClassAndVariableDetails.convertForStoring(entry));
   out.newLine();
  }
  out.flush();
  out.close();
 }
}

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

private static void writeCenter(long id, double[] coordinates, StringBuilder buffer, BufferedWriter out) throws IOException {
    buffer.setLength(0);

    // write id
    buffer.append(id);
    buffer.append(DELIMITER);

    // write coordinates
    for (int j = 0; j < coordinates.length; j++) {
      buffer.append(FORMAT.format(coordinates[j]));
      if (j < coordinates.length - 1) {
        buffer.append(DELIMITER);
      }
    }

    out.write(buffer.toString());
    out.newLine();
  }
}

相关文章