Java Path Create nio createEmptyResourceFile(Path path)

Here you can find the source of createEmptyResourceFile(Path path)

Description

Creates an empty resource file at the given path, assuming the file does not exist already

License

Open Source License

Parameter

Parameter Description
path The Path where the resource file needs to be created.

Declaration

public static void createEmptyResourceFile(Path path) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    private static final String EMPTY_RESOURCE_FILE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<root>\n"
            + "  <xsd:schema id=\"root\" xmlns=\"\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n"
            + "    <xsd:import namespace=\"http://www.w3.org/XML/1998/namespace\" />\n"
            + "    <xsd:element name=\"root\" msdata:IsDataSet=\"true\">\n" + "      <xsd:complexType>\n"
            + "        <xsd:choice maxOccurs=\"unbounded\">\n" + "          <xsd:element name=\"metadata\">\n"
            + "            <xsd:complexType>\n" + "              <xsd:sequence>\n"
            + "                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" />\n"
            + "              </xsd:sequence>\n"
            + "              <xsd:attribute name=\"name\" use=\"required\" type=\"xsd:string\" />\n"
            + "              <xsd:attribute name=\"type\" type=\"xsd:string\" />\n"
            + "              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" />\n"
            + "              <xsd:attribute ref=\"xml:space\" />\n" + "            </xsd:complexType>\n"
            + "          </xsd:element>\n" + "          <xsd:element name=\"assembly\">\n"
            + "            <xsd:complexType>\n"
            + "              <xsd:attribute name=\"alias\" type=\"xsd:string\" />\n"
            + "              <xsd:attribute name=\"name\" type=\"xsd:string\" />\n"
            + "            </xsd:complexType>\n" + "          </xsd:element>\n"
            + "          <xsd:element name=\"data\">\n" + "            <xsd:complexType>\n"
            + "              <xsd:sequence>\n"
            + "                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n"
            + "                <xsd:element name=\"comment\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"2\" />\n"
            + "              </xsd:sequence>\n"
            + "              <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" msdata:Ordinal=\"1\" />\n"
            + "              <xsd:attribute name=\"type\" type=\"xsd:string\" msdata:Ordinal=\"3\" />\n"
            + "              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" msdata:Ordinal=\"4\" />\n"
            + "              <xsd:attribute ref=\"xml:space\" />\n" + "            </xsd:complexType>\n"
            + "          </xsd:element>\n" + "          <xsd:element name=\"resheader\">\n"
            + "            <xsd:complexType>\n" + "              <xsd:sequence>\n"
            + "                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n"
            + "              </xsd:sequence>\n"
            + "              <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" />\n"
            + "            </xsd:complexType>\n" + "          </xsd:element>\n" + "        </xsd:choice>\n"
            + "      </xsd:complexType>\n" + "    </xsd:element>\n" + "  </xsd:schema>\n"
            + "  <resheader name=\"resmimetype\">\n" + "    <value>text/microsoft-resx</value>\n"
            + "  </resheader>\n" + "  <resheader name=\"version\">\n" + "    <value>2.0</value>\n"
            + "  </resheader>\n" + "  <resheader name=\"reader\">\n"
            + "    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n"
            + "  </resheader>\n" + "  <resheader name=\"writer\">\n"
            + "    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n"
            + "  </resheader>\n" + "</data>";

    /**//from   ww w .  j  a  v  a 2 s  .c  o  m
     * Creates an empty resource file at the given path, assuming the file does not exist already
     *
     * @param path
     *         The Path where the resource file needs to be created.
     */
    public static void createEmptyResourceFile(Path path) {
        if (path.toFile().exists()) {
            return;
        }
        try {
            Files.createFile(path);
            Files.write(path, EMPTY_RESOURCE_FILE.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. createDirectoriesIfRequired(@Nonnull Path path)
  2. createDirectory(final Path parent, final String folderName)
  3. createDirectory(Path parent, String name)
  4. createDirectory(Path path)
  5. createDirIfDoesNotExist(String websitesDirPath)
  6. createFile(File root, String path, String filename, String value)
  7. createFile(final Path file, final String line)
  8. createFile(Path filePath, byte[] content)
  9. createFile(Path p)