Java Path Create nio createHeader(Path newFile)

Here you can find the source of createHeader(Path newFile)

Description

create Header

License

LGPL

Declaration

public static void createHeader(Path newFile) 

Method Source Code


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

import java.io.BufferedWriter;
import java.io.IOException;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;

import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static void createHeader(Path newFile) {
        //Writing to file
        try (BufferedWriter writer = Files.newBufferedWriter(newFile, Charset.defaultCharset(),
                new OpenOption[] { StandardOpenOption.APPEND })) {
            Date date = new Date();
            Calendar cal1 = Calendar.getInstance();
            cal1.setTimeInMillis(System.currentTimeMillis());
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-hh:mm:ss");
            String sDate = dateFormat.format(cal1.getTime());
            String developer = System.getProperty("user.name");
            writer.append("*********************************************\n");
            writer.append("**** PROJECTSWG PACKET LOG " + sDate + " ***\n");
            writer.append("*********************************************\n");
            writer.append("DEV: " + developer + "\n");
            writer.append("\n");
            writer.flush();//from   w  ww . ja v  a2 s  .co m
        } catch (IOException exception) {
            System.out.println("Error writing to file");
        }
    }
}

Related

  1. createFileWithContents(String pathString, String contents)
  2. createFolder(String workspacePath)
  3. createFoldersIfNecessary(String workspacePath)
  4. createFullURI(String val, Path parent)
  5. createGlobMatcher(final Path path)
  6. createHiddenFile(String filePath)
  7. createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix)
  8. createJarFile(Path directory, String name, Optional manifest, Class[] classesToAdd, Map filesToAdd)
  9. createJSONFileIfNotExists(Path path)