java.io.FileWriter.write()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(185)

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

FileWriter.write介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * @since 1.568
 */
protected final void createEmptyChangeLog(@Nonnull File changelogFile, @Nonnull TaskListener listener, @Nonnull String rootTag) throws IOException {
  try (FileWriter w = new FileWriter(changelogFile)) {
    w.write("<"+rootTag +"/>");
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: igniterealtime/Smack

@SuppressWarnings("DefaultCharset")
public static void writeFileOrThrow(File file, CharSequence content) throws IOException {
  FileWriter writer = new FileWriter(file, false);
  try {
    writer.write(content.toString());
  } finally {
    writer.close();
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * On Windows, jenkins.war is locked, so we place a new version under a special name,
 * which is picked up by the service wrapper upon restart.
 */
@Override
public void rewriteHudsonWar(File by) throws IOException {
  File dest = getHudsonWar();
  // this should be impossible given the canRewriteHudsonWar method,
  // but let's be defensive
  if(dest==null)  throw new IOException("jenkins.war location is not known.");
  // backing up the old jenkins.war before its lost due to upgrading
  // unless we are trying to rewrite jenkins.war by a backup itself
  File bak = new File(dest.getPath() + ".bak");
  if (!by.equals(bak))
    FileUtils.copyFile(dest, bak);
  String baseName = dest.getName();
  baseName = baseName.substring(0,baseName.indexOf('.'));
  File baseDir = getBaseDir();
  File copyFiles = new File(baseDir,baseName+".copies");
  try (FileWriter w = new FileWriter(copyFiles, true)) {
    w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
  }
}

代码示例来源:origin: evernote/android-job

public static void writeFile(File file, String text, boolean append) throws IOException {
  if (file == null || text == null) {
    throw new IllegalArgumentException();
  }
  if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
    throw new IOException("Could not create parent directory");
  }
  if (!file.exists() && !file.createNewFile()) {
    throw new IOException("Could not create file");
  }
  FileWriter writer = null;
  try {
    writer = new FileWriter(file, append);
    writer.write(text);
  } finally {
    close(writer);
  }
}

代码示例来源:origin: commons-io/commons-io

private void writeTestPayload(final FileWriter fw1, final FileWriterWithEncoding fw2) throws IOException {
  assertTrue(file1.exists());
  assertTrue(file2.exists());
  fw1.write(textContent);
  fw2.write(textContent);
  fw1.write(65);
  fw2.write(65);
  fw1.write(anotherTestContent);
  fw2.write(anotherTestContent);
  fw1.write(anotherTestContent, 1, 2);
  fw2.write(anotherTestContent, 1, 2);
  fw1.write("CAFE", 1, 2);
  fw2.write("CAFE", 1, 2);
  fw1.flush();
  fw2.flush();
}

代码示例来源:origin: alibaba/canal

/**
 * 覆盖本地 canal.properties
 *
 * @param content 远程配置内容文本
 */
private void overrideLocalCanalConfig(String content) {
  try (FileWriter writer = new FileWriter(getConfPath() + "canal.properties")) {
    writer.write(content);
    writer.flush();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: cmusphinx/sphinx4

/** Writes silence to the transcript file. */
private void writeSilenceToTranscript() {
  try {
    float start = getSeconds(totalBytes);
    totalBytes += silenceFileLength;
    float end = getSeconds(totalBytes);
    transcript.write(context + " 1 " + GAP_LABEL + ' ' +
        start + ' ' + end + " \n");
    transcript.flush();
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

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

private static File writeSourceFile(File root, String name, String source) throws IOException {
  File sourceFile = new File(root, name);
  sourceFile.getParentFile().mkdirs();
  try (FileWriter writer = new FileWriter(sourceFile)) {
    writer.write(source);
  }
  return sourceFile;
}

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

/**
 * Writes the given text to the file; either in append mode or replace mode depending
 * the append flag
 */
public static void write(File file, String text, boolean append) throws IOException {
  FileWriter writer = new FileWriter(file, append);
  try {
    writer.write(text);
  } finally {
    writer.close();
  }
}

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

private void writeFile(File newFile, String content) throws IOException {
  try (FileWriter bw = new FileWriter(newFile)) {
   bw.write(content);
  }
  System.out.println("Wrote " + newFile);
 }
}

代码示例来源:origin: alibaba/canal

/**
 * 覆盖本地application.yml文件
 *
 * @param content 文件内容
 */
private void overrideLocalCanalConfig(String content) {
  try (FileWriter writer = new FileWriter(getConfPath() + "application.yml")) {
    writer.write(content);
    writer.flush();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
}

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

private void createDashboardConfigFile() throws IOException {
  try (FileWriter fw = createOrGetFile(webDir, "config")) {
    fw.write(createConfigJson(DashboardConfiguration.from(webRefreshIntervalMillis, ZonedDateTime.now())));
    fw.flush();
  } catch (IOException ioe) {
    LOG.error("Failed to write config file.");
    throw ioe;
  }
}

代码示例来源:origin: twosigma/beakerx

public void saveToFile(String json){
  try {
    File file = new File("beakerx_inspect.json");
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(json);
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

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

@Test
void databaseThatRequireRecoveryIsNotDumpable() throws IOException
{
  File logFile = new File( databaseDirectory.toFile(), TransactionLogFiles.DEFAULT_NAME + ".0" );
  try ( FileWriter fileWriter = new FileWriter( logFile ) )
  {
    fileWriter.write( "brb" );
  }
  CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db" ) );
  assertThat( commandFailed.getMessage(), startsWith( "Active logical log detected, this might be a source of inconsistencies." ) );
}

代码示例来源:origin: remkop/picocli

private void writeToFile(String result) throws IOException {
    FileWriter writer = null;
    try {
      writer = new FileWriter(outputFile);
      writer.write(result);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
}

代码示例来源:origin: commons-io/commons-io

/** Append some lines to a file */
private void write(final File file, final String... lines) throws Exception {
  try (FileWriter writer = new FileWriter(file, true)) {
    for (final String line : lines) {
      writer.write(line + "\n");
    }
  }
}

代码示例来源:origin: Netflix/Priam

@Override
protected void downloadFileImpl(Path remotePath, Path localPath) throws BackupRestoreException {
  AbstractBackupPath path = pathProvider.get();
  path.parseRemote(remotePath.toString());
  if (path.getType() == AbstractBackupPath.BackupFileType.META) {
    // List all files and generate the file
    try (FileWriter fr = new FileWriter(localPath.toFile())) {
      JSONArray jsonObj = new JSONArray();
      for (AbstractBackupPath filePath : flist) {
        if (filePath.type == AbstractBackupPath.BackupFileType.SNAP
            && filePath.time.equals(path.time)) {
          jsonObj.add(filePath.getRemotePath());
        }
      }
      fr.write(jsonObj.toJSONString());
      fr.flush();
    } catch (IOException io) {
      throw new BackupRestoreException(io.getMessage(), io);
    }
  }
  downloadedFiles.add(remotePath.toString());
}

代码示例来源:origin: zendesk/maxwell

@Override
  public void push(RowMap r) throws Exception {
    String output = r.toJSON(outputConfig);

    if ( output != null ) {
      this.fileWriter.write(r.toJSON(outputConfig));
      this.fileWriter.write('\n');
      this.fileWriter.flush();
    }

    context.setPosition(r);
  }
}

相关文章