Java Path Create nio createFile(String filePath, String content)

Here you can find the source of createFile(String filePath, String content)

Description

create File

License

Apache License

Declaration

public static void createFile(String filePath, String content) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.nio.charset.Charset;

public class Main {
    public static void createFile(String filePath, String content) {
        File file = new File(filePath);
        try {//w  ww  .  ja  v  a2s  . c  o  m
            if (!file.exists()) {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                file.createNewFile();
            }

            FileOutputStream fos = new FileOutputStream(file);
            fos.write(content.getBytes(Charset.forName("UTF-8")));
            fos.flush();
            fos.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. createFile(Path p)
  2. createFile(Path path)
  3. createFile(Path path)
  4. createFile(Path path)
  5. createFile(Path path)
  6. createFile(String workspacePath)
  7. createFileForReport(Path reportDir, String filePrefix, String fileSuffix)
  8. createFileFromText(String sourceText, IPath path)
  9. createFileIfNotExist(Path path)