Java Path File Name nio saveFileFromByteArray(String filename, String pathDirectory, byte[] data)

Here you can find the source of saveFileFromByteArray(String filename, String pathDirectory, byte[] data)

Description

save File From Byte Array

License

Apache License

Parameter

Parameter Description
filename a parameter
pathDirectory a parameter
data a parameter

Return

Status of save opereration

Declaration

public static boolean saveFileFromByteArray(String filename, String pathDirectory, byte[] data) 

Method Source Code


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

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

public class Main {
    /**//  w  w w .j  a  v  a2  s  .  c  o  m
     * 
     * @param filename
     * @param pathDirectory
     * @param data
     * @return Status of save opereration
     */
    public static boolean saveFileFromByteArray(String filename, String pathDirectory, byte[] data) {
        Path path = Paths.get(pathDirectory);
        if (Files.isDirectory(path)) {
            Path completePathToSaveFile = Paths.get(path.toString(), filename);
            if (!Files.exists(completePathToSaveFile)) {
                try {
                    Files.write(completePathToSaveFile, data);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }

    }
}

Related

  1. readFileFromPath(String filename)
  2. relativizePath(Path relativeTo, String filename)
  3. rename(Path origin, Path destination)
  4. renameFile(Path filePath, String postfix)
  5. renameLogFile(Path original)
  6. saveNamesToFile(Map namesMap, Path namesFile)
  7. saveToFile(String content, String directoryPath, String filename)
  8. shortenFileName(Path file, List dirs)
  9. storeFile(String fileName, InputStream inputStream, Path targetPath)