Class FileAccess

java.lang.Object
de.edgesoft.edgeutils.files.FileAccess

public class FileAccess
extends java.lang.Object
Class providing usual file access operations.

Legal stuff

Copyright 2010-2020 Ekkart Kleinod ekleinod@edgesoft.de

This file is part of edgeutils.

edgeutils is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

edgeutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with edgeutils. If not, see http://www.gnu.org/licenses/.

Since:
0.1
Author:
Ekkart Kleinod
  • Constructor Summary

    Constructors 
    Constructor Description
    FileAccess()  
  • Method Summary

    Modifier and Type Method Description
    static java.nio.charset.Charset getEncoding()
    Returns the current file encoding.
    static java.lang.String readFile​(java.nio.file.Path theFilePath)
    Read content of a file.
    static void setEncoding​(java.nio.charset.Charset newEncoding)
    Sets the file encoding.
    static void writeFile​(java.nio.file.Path theFileName, java.lang.String theContent)
    Write content to a file.
    static void writeFile​(java.nio.file.Path theFileName, java.util.List<java.lang.String> theContent)
    Write list content to a file.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • setEncoding

      public static void setEncoding​(java.nio.charset.Charset newEncoding)
      Sets the file encoding.

      For the standard encodings see java.nio.charsets.StandardCharsets.

      Use them as follows, example: UTF-8:

      
         FileAccess.setEncoding(StandardCharsets.UTF_8);
       
      Parameters:
      newEncoding - the file encoding
    • getEncoding

      public static java.nio.charset.Charset getEncoding()
      Returns the current file encoding.
      Returns:
      the file encoding
      Since:
      0.11.0
    • readFile

      public static java.lang.String readFile​(java.nio.file.Path theFilePath) throws java.lang.Exception
      Read content of a file.
      Parameters:
      theFilePath - filepath
      Returns:
      file content
      Throws:
      java.lang.Exception - if one occurs
    • writeFile

      public static void writeFile​(java.nio.file.Path theFileName, java.lang.String theContent) throws java.io.IOException
      Write content to a file. This method creates the whole path to the file, if it does not exist.
      Parameters:
      theFileName - filename
      theContent - file content
      Throws:
      java.io.IOException - if one occurs
    • writeFile

      public static void writeFile​(java.nio.file.Path theFileName, java.util.List<java.lang.String> theContent) throws java.io.IOException
      Write list content to a file.

      This method creates the whole path to the file, if it does not exist.

      Parameters:
      theFileName - filename
      theContent - file content (list)
      Throws:
      java.io.IOException - if one occurs
      Since:
      0.5.0