fstest.java
/*
* Copyright (c) 2001-2005 Servertec. All Rights Reserved.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* THIS NOTICE MUST NOT BE ALTERED NOR REMOVED.
*
* CopyrightVersion 1.0
*/
import stec.sfc.Win32.RandomAccessFile;
import stec.sfc.Win32.FileAccessMode;
import stec.sfc.Win32.FileShareMode;
import stec.sfc.Win32.FileOperation;
import stec.sfc.Win32.FileAttribute;
import stec.sfc.Win32.Console;
import stec.sfc.Win32.FileSystem;
import stec.sfc.Win32.FileSystem;
import stec.sfc.Win32.File;
public class fstest
{
public static void main(String[] args) throws Exception
{
System.out.println("Windows Directory: " + FileSystem.getWindowsDirectory());
System.out.println("System Directory: " + FileSystem.getSystemDirectory());
String tempdir = FileSystem.getTempPath();
System.out.println("TEMP Directory: " + tempdir);
String current_directory = FileSystem.getCurrentDirectory();
System.out.println("currentDirectory: " + current_directory);
FileSystem.setCurrentDirectory(tempdir);
String path = FileSystem.getCurrentDirectory();
if(!path.equalsIgnoreCase(path))
{
System.out.println("unable to change current directory: " + path);
}
else
{
System.out.println("change current directory: " + path);
}
FileSystem.setCurrentDirectory(current_directory);
path = FileSystem.getCurrentDirectory();
if(!path.equalsIgnoreCase(path))
{
System.out.println("unable to change current directory: " + path);
}
else
{
System.out.println("change current directory: " + path);
}
RandomAccessFile fhandle = new RandomAccessFile(tempdir + "test0.dat", FileAccessMode.READ | FileAccessMode.WRITE, FileShareMode.READ | FileShareMode.WRITE, FileOperation.OPEN_ALWAYS, FileAttribute.NORMAL);
fhandle.write("testdata".getBytes());
fhandle.close();
try
{
System.out.println("copy");
FileSystem.copy(tempdir + "test0.dat", tempdir + "test1.dat", true);
}
catch(Exception ex)
{
ex.printStackTrace();
}
try
{
System.out.println("rename");
FileSystem.rename(tempdir + "test1.dat", tempdir + "test2.dat", true);
}
catch(Exception ex)
{
ex.printStackTrace();
}
try
{
System.out.println("delete");
FileSystem.delete(tempdir + "test0.dat");
}
catch(Exception ex)
{
ex.printStackTrace();
}
try
{
System.out.println("delete");
FileSystem.delete(tempdir + "test2.dat");
}
catch(Exception ex)
{
ex.printStackTrace();
}
String filename = FileSystem.getTempFileName(tempdir, "tst", 0);
System.out.println("temp filename: " + filename);
try
{
FileSystem.delete(filename);
}
catch(Exception ex) {}
filename = FileSystem.getTempFileName(tempdir, "tst", 1);
System.out.println("temp filename: " + filename);
try
{
FileSystem.delete(filename);
}
catch(Exception ex) {}
System.out.println("create temp file");
File file = FileSystem.createTempFile(tempdir, "tst");
System.out.println("file: " + file.toString());
file.delete();
System.out.println("create temp file");
file = FileSystem.createTempFile(new File(tempdir), "tst");
System.out.println("file: " + file.toString());
file.delete();
System.out.println("create temp file");
file = FileSystem.createTempFile("tst");
System.out.println("file: " + file.toString());
file.delete();
}
}