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

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

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

FileWriter.close介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public void release() throws Exception {
    writer.flush();
    writer.close();
  }
}

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

/**
 * Used by gemfire build.xml to generate a default gemfire.properties for use by applications. See
 * bug 30995 for the feature request.
 */
public static void main(String args[]) throws IOException {
 FileWriter fw = new FileWriter(new File("cache.xml"));
 PrintWriter pw = new PrintWriter(fw);
 generateDefault(pw);
 pw.close();
 fw.close();
}

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

public boolean build(Language language) throws IOException {
  settingsFile = File.createTempFile("libgdx-setup-settings", ".gradle");
  buildFile = File.createTempFile("libgdx-setup-build", ".gradle");
  if (!settingsFile.exists()) {
    settingsFile.createNewFile();
  if (!buildFile.exists()) {
    buildFile.createNewFile();
  buildFile.setWritable(true);
  try {
    FileWriter settingsWriter = new FileWriter(settingsFile.getAbsoluteFile());
    BufferedWriter settingsBw = new BufferedWriter(settingsWriter);
    String settingsContents = "include ";
    settingsWriter.close();
    FileWriter buildWriter = new FileWriter(buildFile.getAbsoluteFile());
    BufferedWriter buildBw = new BufferedWriter(buildWriter);
    buildWriter.close();
    return true;
  } catch (IOException e) {

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

@SuppressWarnings("checkstyle:emptyblock")
@Override public void handleMessage(@NonNull Message msg) {
 String content = (String) msg.obj;
 FileWriter fileWriter = null;
 File logFile = getLogFile(folder, "logs");
 try {
  fileWriter = new FileWriter(logFile, true);
  writeLog(fileWriter, content);
  fileWriter.flush();
  fileWriter.close();
 } catch (IOException e) {
  if (fileWriter != null) {
   try {
    fileWriter.flush();
    fileWriter.close();
   } catch (IOException e1) { /* fail silently */ }
  }
 }
}

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

static void convertFile(File f) throws IOException {
  File fullPath = f.getAbsoluteFile();
  File dir = fullPath.getParentFile();
  String filename = fullPath.getName();
  File convertedFile = new File(dir, filename + ".canonical");
  config.setDirectoryForTemplateLoading(dir);
  Template template = config.getTemplate(filename);
  FileWriter output = new FileWriter(convertedFile);
  try {
    template.dump(output);
  } finally {
    output.close();
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Sync the map of clients out to disk.
 */
@SuppressWarnings("serial")
private void write() {
  try {
    if (!file.exists()) {
      // create a new file
      logger.info("Creating saved clients list in " + file);
      file.createNewFile();
    }
    FileWriter out = new FileWriter(file);
    gson.toJson(clients, new TypeToken<Map<String, RegisteredClient>>(){}.getType(), out);
    out.close();
  } catch (IOException e) {
    logger.error("Could not write to output file", e);
  }
}

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

private void writeCheckmarks(String habitDirName, CheckmarkList checkmarks)
  throws IOException
{
  String filename = habitDirName + "Checkmarks.csv";
  FileWriter out = new FileWriter(exportDirName + filename);
  generateFilenames.add(filename);
  checkmarks.writeCSV(out);
  out.close();
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void get( String arg0, String arg1 ) throws IOException, FTPException {
 FileWriter fw = null;
 try {
  Random r = new Random();
  fw = new FileWriter( arg0 );
  for ( int i = 0; i < 100; i++ ) {
   fw.append( (char) ( r.nextInt( 83 ) + 32 ) );
  }
  fw.flush();
  fw.close();
 } finally {
  if ( fw != null ) {
   fw.close();
  }
 }
}

代码示例来源:origin: uber-common/jvm-profiler

@Override
public synchronized void close() {
  closed = true;
  
  List<FileWriter> copy = new ArrayList<>(fileWriters.values());
  for (FileWriter entry : copy) {
    try {
      entry.flush();
      entry.close();
    } catch (IOException e) {
      e.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/ignite

/**
 * @throws Exception If failed.
 */
private void prepareJaasConfigFile() throws Exception {
  U.ensureDirectory(tmpDir, "Temp directory for JAAS configuration file wasn't created", null);
  File saslConfFile = new File(tmpDir, JAAS_CONF_FILE);
  FileWriter fwriter = new FileWriter(saslConfFile);
  writeServerConfigSection(fwriter, "validPassword");
  writeClientConfigSection(fwriter, "ValidZookeeperClient", "validPassword");
  writeClientConfigSection(fwriter, "InvalidZookeeperClient", "invalidPassword");
  fwriter.close();
}

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

private void writeScores(String habitDirName, ScoreList scores)
  throws IOException
{
  String path = habitDirName + "Scores.csv";
  FileWriter out = new FileWriter(exportDirName + path);
  generateFilenames.add(path);
  scores.writeCSV(out);
  out.close();
}

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

FileWriter fw = new FileWriter(temp);
yaml.dump(confMap, fw);
fw.flush();
fw.close();

代码示例来源:origin: android10/Android-CleanArchitecture

/**
 * Writes a file to Disk.
 * This is an I/O operation and this method executes in the main thread, so it is recommended to
 * perform this operation using another thread.
 *
 * @param file The file to write to Disk.
 */
void writeToFile(File file, String fileContent) {
 if (!file.exists()) {
  try {
   final FileWriter writer = new FileWriter(file);
   writer.write(fileContent);
   writer.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

相关文章