FileUtils Class Reference

List of all members.

Public Types

 OPEN
enum  FileChooserType { OPEN, SAVE }
 Either show a save or open dialog.

Static Public Member Functions

static void copy (File srcFileOrDir, File targetFileOrDir)
static void copy (File sourceFileOrDir, File targetFileOrDir, boolean visibleFilesOnly) throws IOException
 A flexible copy function.
static JFileChooser createNewFileChooser (String[] extensions)
static void downloadUrlToFile (URL url, File result) throws IOException
static String getCurrentTimeForUseInAFileName ()
static String getCurrentTimeForUseInASortableFileName ()
static boolean isHiddenOrDotFile (final File possiblyHiddenFile)
static List< File > listVisibleDirs (File path)
 Return only directories (that are children of the given path) that are not hidden.
static List< File > listVisibleFiles (File path, String...extensionFilter)
 Return only files (that are children of the given path) that are not hidden.
static List< File > listVisibleFilesRecursively (File path)
static List< File > listVisibleFilesRecursively (File path, String[] extensionFilter)
static StringBuilder readFileIntoStringBuffer (File f)
 Reads an entire file into the StringBuilder (faster than StringBuffer).
static StringBuilder readFileIntoStringBuffer (File f, boolean separateWithNewLines)
 Includes the workaround for bug in setting the user.dir: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557.
static File showDirectoryChooser (Component parent, String title)
 Only allows directory selection.
static File showFileChooser (File initialPath, FileChooserType type, Component parent, String[] extensions, String title)
static void sortByLastModified (List< File > files, final SortDirection direction)
static void sortPhotosByCaptureDate (List< File > files, final SortDirection direction)
 For JPEGs.
static void writeStringToFile (String string, File destFile)
 Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557.
static void writeStringToFileOnlyIfNew (String string, File file)

Detailed Description

Utilities for manipulating Paths, Files, Directories, etc.

This software is distributed under the BSD License.

Author:
Ron B Yeh (ronyeh(AT)cs.stanford.edu)

Definition at line 49 of file FileUtils.java.


Member Function Documentation

static void copy ( File  sourceFileOrDir,
File  targetFileOrDir,
boolean  visibleFilesOnly 
) throws IOException [static]

A flexible copy function.

It will do slightly different things depending on what is passed into the parameters. It can copy a file to another file, into a directory, or a directory into another directory.

Parameters:
sourceFileOrDir 
targetFileOrDir 
b 
Exceptions:
IOException 

Definition at line 83 of file FileUtils.java.

static JFileChooser createNewFileChooser ( String[]  extensions  )  [static]

Parameters:
extensions should NOT have a . in front of them... i.e., xml, and NOT .xml
Returns:

Definition at line 189 of file FileUtils.java.

Referenced by FileUtils.showFileChooser().

static void downloadUrlToFile ( URL  url,
File  result 
) throws IOException [static]

Parameters:
url 
result 
Exceptions:
IOException 

Definition at line 201 of file FileUtils.java.

static String getCurrentTimeForUseInAFileName (  )  [static]

Returns:
The current time, with symbols replaced with underscores, so that we can use it in file names. This is great for logs that have to be tagged with dates.

Definition at line 241 of file FileUtils.java.

static String getCurrentTimeForUseInASortableFileName (  )  [static]

Returns:

Definition at line 252 of file FileUtils.java.

static boolean isHiddenOrDotFile ( final File  possiblyHiddenFile  )  [static]

Parameters:
possiblyHiddenFile 
Returns:
if the file is hidden (either hidden flag, or name starts with a dot)

Definition at line 276 of file FileUtils.java.

static List<File> listVisibleDirs ( File  path  )  [static]

Return only directories (that are children of the given path) that are not hidden.

Parameters:
path 
Returns:

Definition at line 286 of file FileUtils.java.

static List<File> listVisibleFiles ( File  path,
String...  extensionFilter 
) [static]

Return only files (that are children of the given path) that are not hidden.

TODO/BUG: Doesn't use FileExcludeHiddenFilter??

Parameters:
path 
extensionFilter 

Definition at line 299 of file FileUtils.java.

static List<File> listVisibleFilesRecursively ( File  path,
String[]  extensionFilter 
) [static]

Parameters:
path 
extensionFilter 
Returns:
a List of Files (guaranteed to be files, because if it's a dir, it will drill down)

Definition at line 341 of file FileUtils.java.

static List<File> listVisibleFilesRecursively ( File  path  )  [static]

Parameters:
path 
Returns:

Definition at line 309 of file FileUtils.java.

static StringBuilder readFileIntoStringBuffer ( File  f,
boolean  separateWithNewLines 
) [static]

Includes the workaround for bug in setting the user.dir: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557.

Parameters:
f turn this file into a big string buffer (StringBuilder for efficiency)
separateWithNewLines 
Returns:

Definition at line 399 of file FileUtils.java.

static StringBuilder readFileIntoStringBuffer ( File  f  )  [static]

Reads an entire file into the StringBuilder (faster than StringBuffer).

Parameters:
f 
Returns:
the StringBuilder containing all the data

Definition at line 386 of file FileUtils.java.

static File showDirectoryChooser ( Component  parent,
String  title 
) [static]

Only allows directory selection.

Returns:
the chosen directory, or null if the user canceled.

Definition at line 428 of file FileUtils.java.

static File showFileChooser ( File  initialPath,
FileChooserType  type,
Component  parent,
String[]  extensions,
String  title 
) [static]

Parameters:
initialPath 
type 
parent 
extensions 
title 
Returns:

Definition at line 452 of file FileUtils.java.

References FileUtils.createNewFileChooser().

static void sortByLastModified ( List< File >  files,
final SortDirection  direction 
) [static]

Parameters:
files 
Returns:

Definition at line 481 of file FileUtils.java.

static void sortPhotosByCaptureDate ( List< File >  files,
final SortDirection  direction 
) [static]

For JPEGs.

...

This is a little bit slow, as it takes 4.3 seconds for about 670 files. Can we speed this up through a cache? After implementing the cache, it takes about 875 ms to sort 670 files. This is because we only read each file once, and save the timestamp in memory.

Parameters:
files 
direction 

Definition at line 519 of file FileUtils.java.

static void writeStringToFile ( String  string,
File  destFile 
) [static]

Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557.

Parameters:
string 
destFile Jun 5, 2006
Author:
Ron Yeh

Definition at line 576 of file FileUtils.java.

Referenced by FileUtils.writeStringToFileOnlyIfNew().

static void writeStringToFileOnlyIfNew ( String  string,
File  file 
) [static]

Parameters:
string 
file Mar 14, 2006
Author:
Ron Yeh

Definition at line 598 of file FileUtils.java.

References FileUtils.writeStringToFile().


The documentation for this class was generated from the following file:
Generated on Sat Apr 14 18:21:46 2007 for R3 Paper Toolkit by  doxygen 1.4.7