Java 8 FileWriter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 FileWriter class.

This code example shows how to use the following methods:
 
    @Override 
    public void start() { 
        final File file = new File(path);
        try { 
            final BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            final OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
            try { 
                System.out.println("--- writing");
                writer.write("Test\n");
            } finally { 
                try { 
                    writer.close();
                    System.out.println("--- written");
                } catch (Exception ignore) {
                } 
            } 
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:flush
	} 
 
	protected void initFile(File file) {
		Writer writer = null;
		try { 
			writer = new FileWriter(file);
			initFile(writer);
			writer.flush();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally { 
			try { 
				StreamUtils.close(writer);
			} catch (Exception e) {
				throw new RuntimeException(e);
			} 
		}		 
	} 
	 
	protected File createFile() {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, flush
			File parent = file.getParentFile();
			if (!parent.exists()) {
				parent.mkdirs();
			} 
 
			writer = new FileWriter(file);
			template.process(root, writer);
 
		} catch (Exception e) {
			e.printStackTrace();
 
		} finally { 
			if (writer != null) {
				try { 
					writer.flush();
					writer.close();
 
				} catch (IOException e) {
					e.printStackTrace();
				} 
			} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
  /* 
   * Test refreshing an existing HostsFileReader with an includes file that no longer exists 
   */ 
  @Test 
  public void testRefreshHostFileReaderWithNonexistentFile() throws Exception { 
    FileWriter efw = new FileWriter(excludesFile);
    FileWriter ifw = new FileWriter(includesFile);
 
    efw.close();
 
    ifw.close();
 
    HostsFileReader hfp = new HostsFileReader(includesFile, excludesFile);
    assertTrue(INCLUDES_FILE.delete());
    try { 
      hfp.refresh();
      Assert.fail("Should throw FileNotFoundException");
    } catch (FileNotFoundException ex) {
      // Exception as expected 
    } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, write
    if (pidfile != null && pid != null) {
      File f = new File(pidfile);
      f.deleteOnExit();
 
      try { 
        FileWriter fw = new FileWriter(f);
        fw.write(pid);
        fw.close();
      } catch (IOException e) {
        LOG.error("failed to drop a pid file", e);
        System.exit(-1);
      } 
      LOG.info("Dropped a pidfile='" + pidfile + "' with pid=" + pid);
    } else { 
      LOG.warn("No pid or pidfile system property specified."); 
    } 
 
    String interactiveprop = System.getProperty("fwdstdin");
    boolean interactive = (interactiveprop != null);
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:write, write
 
		String tmpDir = System.getProperty("java.io.tmpdir");
		 
		File outputFile = new File(tmpDir + "/converterOutput.txt");
		try { 
			FileWriter out = new FileWriter(outputFile);
			out.write("---------- Start-------");
			out.write("Converter for the build object : '" + buildObj.getName() + "' is invoked.");
			out.write("From Id : " + fromId );
			out.write("To Id : " + toId);
			out.write("---------- End-------");
		} catch (IOException e) {
			// TODO Auto-generated catch block 
		//	e.printStackTrace(); 
			System.out.println("Exception raised.");
		} 
		 
	 
	return buildObj;
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        setWriter(textOutput, false);
    } 
 
    public void setOutputFile(File file) throws IOException {
        cleanupWriter(); 
        setWriter(new StreamingStyledTextOutput(new BufferedWriter(new FileWriter(file))), true);
    } 
 
    public void startProject(Project project) {
        String header = createHeader(project);
        builder.heading(header);
    } 
 
    protected String createHeader(Project project) {
        String header;
        if (project.getRootProject() == project) {
            header = "Root project";
        } else { 
            header = String.format("Project %s", project.getPath());
        } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, write
        try { 
            FileReader reader = new FileReader(counterFile);
            callsCounter = reader.read();
            reader.close();
            callsCounter++;
            FileWriter writer = new FileWriter(counterFile);
            writer.write(callsCounter);
            writer.close();
        } catch (IOException ex) {
            throw new RuntimeException("File for counting IO exception", ex);
        } 
 
        return callsCounter;
    } 
 
    /** 
     * Set number in File to 0 
     */ 
    public void resetFileCounter() { 
        try { 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, flush, write
			File f = new File(jobContext.getWorkDir() + File.separator
					+ UDF_SQL_NAME);
			if (f.exists()) {
				f.delete();
			} 
			FileWriter fos = new FileWriter(f);
			fos.write(file.getContent());
			fos.flush();
			fos.close();
			return true; 
		} catch (Exception e) {
			log("获取同步表脚本失败"); 
			log(e);
			return false; 
		} 
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
   * @param conf Configuration contents to write to file 
   * @throws IOException if there is an I/O error saving the file 
   */ 
  public static void saveConfig(File file, Configuration conf)
      throws IOException { 
    Writer writer = new FileWriter(file);
    try { 
      conf.writeXml(writer);
    } finally { 
      writer.close();
    } 
  } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 FileWriter Questions & Answers:

See Code Examples for Java 8 FileWriter Methods: