Class DiscFile

java.lang.Object
de.elo.ix.jscript.FileBase
de.elo.ix.jscript.DiscFile

public class DiscFile extends FileBase
This class provides convenient methods to read and write from files.

Write Text File

The following lines show how to write a text file. The characters are encode in the UTF-16LE format. The appropriate Byte Order Mark (BOM) is inserted at the beginning of the file.
  
    var textFile = new Packages.de.elo.ix.jscript.DiscFile("c:\\mytext.txt", "UTF-16LE");
    textFile.writeAllText(content);
 
 

Read Text File

The following lines show how to read a text file. If the file starts with a Byte Order Mark, the characters are read with the related encoding.
  
    var textFile = new Packages.de.elo.ix.jscript.DiscFile("c:\\mytext.txt");
    var content = textFile.readAllText();
 
 

Move or rename a File

The function renameTo can be used to rename or move a file.
  
    var file = new Packages.de.elo.ix.jscript.DiscFile("c:\\mytext.txt");
    file.renameTo("c:\\temp\\mytext1.txt");
 
 

Delete a File

The function remove deletes a file.
  
    var file = new Packages.de.elo.ix.jscript.DiscFile("c:\\mytext.txt");
    if (file.exists()) {
      if (!file.remove()) {
        throw "Cannot remove file=" + file);
      }
    }
 
 
  • Constructor Details

    • DiscFile

      public DiscFile(String fileName)
      Constructor This object uses the default character set when writing a text file. The Byte Order Mark is dectected, if a text file is to be read.
      Parameters:
      fileName - File name
      See Also:
    • DiscFile

      public DiscFile()
      Constructor. This constructor prepares a temporary file that is created in the write functions. It uses the default character set when writing a text file.
      See Also:
    • DiscFile

      public DiscFile(String fileName, String charset)
      Constructor. This object uses the giben character set when writing a text file. The Byte Order Mark is dectected, if a text file is to be read.
      Parameters:
      fileName - File name
      charset - Optional. Default character set to be used in read and write functions.
      See Also:
  • Method Details

    • exists

      public boolean exists()
      Returns true, if the file exists.
      Returns:
      true, if the file exists.
    • remove

      public boolean remove()
      Deletes fileName. The function returns true, if the file or directory has been deleted. If the file or directory cannot be deleted, the function returns false and does not throw an exception.
      Returns:
      true, if the file has been deleted.
    • renameTo

      public boolean renameTo(String newFileName)
      Renames or moves a file. The function returns true, if the file or directory has been renamed. If the file or directory cannot be deleted, the function returns false or throws an exception. The directory hierarchy of the destination file is created if it does not exist.
      Parameters:
      newFileName - Destination file.
      Returns:
      true, if the file has been renamed or moved.
    • toString

      public String toString()
      Returns the file name.
      Overrides:
      toString in class Object
    • setName

      public void setName(String fileName)
      Set the file name.
      Parameters:
      fileName - File name
    • getName

      public String getName()
      Get the file name.
      Returns:
      File name