|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.Files
public abstract class Files
Files is a utility class that contains static methods for handling files and directories
Nested Class Summary | |
---|---|
static interface |
Files.BufferingFilter
Description: Buffering filter stores some data, and these data can be retrieved later. |
static interface |
Files.ByteFilter
Description: The interface is used to define filters for filtering data in pipes. |
Field Summary | |
---|---|
static java.io.FileFilter |
DIRECTORY_FILTER
directoryFilter is a FileFilter that accepts directories only |
static java.io.FileFilter |
fileFilter
fileFilter is a FileFilter that accepts files only |
static int |
FIND_ALL
|
static int |
FIND_DIRECTORY
|
static int |
FIND_FILE
|
static boolean |
USE_NIO
copy copies a file or a directory to another |
Constructor Summary | |
---|---|
Files()
|
Method Summary | |
---|---|
static int |
adjustSizeByMooreLaw(int size,
int thisYear)
Adjusts buffer size according to Moore's law |
static java.io.File |
appendBytesToFile(byte[] data,
java.lang.String fileTo)
Appends bytes to a file |
static java.io.File |
appendBytesToFile(char[] data,
java.lang.String fileTo)
Appends bytes to the end of a file |
static java.io.File |
appendToFile(byte[] data,
java.lang.String fileTo)
Appends bytes to the end of a file |
static java.io.File |
appendToFile(char[] data,
java.lang.String fileTo)
Appends chars to the end of a file |
static java.io.File |
appendToFile(java.lang.CharSequence data,
java.lang.String fileTo)
Appends a char sequence to the end of a file |
static java.lang.Iterable<java.lang.Byte> |
bytes(java.io.File file)
returns an Iterable<Byte> that scans over the bytes in a File |
static java.lang.Iterable<java.lang.Byte> |
bytes(java.io.InputStream is)
returns an Iterable<Byte> enclosure that scans over the bytes returned by InputStream |
static java.lang.Iterable<java.lang.Character> |
chars(java.io.File file)
returns an Iterable<Character> that scans over the characters in a File |
static java.lang.Iterable<java.lang.Character> |
chars(java.io.Reader reader)
returns an Iterable<Character> enclosure that scans over the characters returned by Reader |
static int |
compare(java.io.File left,
java.io.File right)
Compare two files |
static boolean |
copy(java.io.File from,
java.io.File to)
|
static boolean |
copy(java.io.File from,
java.io.File to,
java.lang.String what)
copy copies a file or a directory from one directory to another |
static boolean |
copy(java.lang.String from,
java.lang.String to)
copy copies a file or a directory to another |
static boolean |
copy(java.lang.String from,
java.lang.String to,
java.lang.String what)
copies a file or a directory from one directory to another |
static boolean |
deleteFile(java.io.File file)
Deletes a file or a directory (with all its contents, they say it is dangerous) |
static boolean |
deleteFile(java.lang.String filename)
Deletes a file or a directory (with all its contents, they say it is dangerous) |
static java.lang.String |
dirname(java.io.File file)
Calculates directory path for a file (like in Perl) |
static java.lang.String |
dirname(java.lang.String path)
Calculates directory path by file path (like in Perl) |
static boolean |
equal(java.io.File left,
java.io.File right)
compares two files or directories, recursively |
static java.lang.String |
filename(java.lang.String path)
Calculates filename by file path (like in Perl) |
static java.lang.Iterable<java.io.File> |
files(java.io.File folder)
Returns an Iterable<File> that scans all files in the folder |
static java.util.List<java.lang.String> |
find(java.io.File subdir,
java.util.regex.Pattern pattern)
Lists recursively files and directories with name matching a regexp |
static java.util.List<java.lang.String> |
find(java.lang.String subdir,
java.util.regex.Pattern pattern)
Lists recursively files and directories with name matching a regexp |
static java.util.List<java.lang.String> |
find(java.lang.String subdir,
java.lang.String pattern)
Lists recursively files and directories with name matching a regexp |
static java.lang.String |
findLatest(java.lang.String subdir,
java.lang.String pattern)
Finds latest file or directory which name matches a pattern |
static java.lang.String |
findLatest(java.lang.String subdir,
java.lang.String pattern,
int whatExactly)
Finds latest file or directory or one of these which name matches a pattern |
static java.lang.String |
findLatestDirectory(java.lang.String subdir,
java.lang.String pattern)
Finds latest directory which name matches a pattern |
static java.lang.String |
findLatestFile(java.lang.String subdir,
java.lang.String pattern)
Finds latest file which name matches a pattern |
static java.lang.String |
getcwd()
Gets current directory path |
static java.lang.String |
getFullPath(java.io.File file)
Calculates full path of a file |
static java.lang.String |
getFullPath(java.lang.String path)
Calculates full path of a file by its path |
static java.lang.String |
getPackageName(java.lang.String basePath,
java.lang.String currentPath)
Calculates a java package name by directory name and base directory name |
static boolean |
install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.io.File location)
installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory |
static boolean |
install(java.lang.Class clazz,
java.lang.String resourceArchiveName,
java.lang.String folderName)
installs files from a resource archive Reads a specified resource for aspecified class, unzips it to a specified directory |
static boolean |
install(java.lang.String urlString,
java.lang.String directoryName)
installs files from a URL Reads the contents of the specified URL, unzips it to a specified directory |
static boolean |
install(java.net.URL url,
java.io.File location)
installs files from a URL Reads the contents of the specified URL, unzips it to a specified directory |
static java.lang.String |
lastModified(java.io.File file)
Gets file modification date/time as a string |
static java.lang.Iterable<java.lang.String> |
lines(java.io.File file)
returns an Iterable<String> that scans over the lines in a File |
static java.lang.Iterable<java.lang.String> |
lines(java.io.Reader reader)
returns an Iterable<String> enclosure that scans over the lines returned by Reader |
static java.io.File[] |
listFiles(java.io.File dir)
Lists files in a directory |
static java.io.File[] |
listSubdirectories(java.io.File dir)
Lists subdirectories of a directory |
static java.io.FileOutputStream |
makeFile(java.io.File file)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.io.File file,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String... path)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String path)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String[] path,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String path,
boolean append)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String dir,
java.lang.String filename)
Creates or opens a file for output. |
static java.io.FileOutputStream |
makeFile(java.lang.String dirname,
java.lang.String filename,
boolean append)
Creates or opens a file for output. |
static java.io.OutputStreamWriter |
makeFileWriter(java.lang.String path,
java.lang.String encoding)
Creates or opens a file for output. |
static java.lang.String |
path(java.lang.String currentDir,
java.lang.String filepath)
Having a directory and file path (relative or absolute) calculates full path |
static void |
pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking)
pipes data from input stream to output stream |
static void |
pipe(java.io.InputStream in,
java.io.OutputStream out,
boolean isBlocking,
Files.ByteFilter filter)
pipes data from input stream to output stream, possibly pumping them through the filter (if any) |
static boolean |
pipe(java.io.Reader in,
java.io.Writer out)
pipes data from input stream to output stream |
static byte[] |
readBytesFromFile(java.lang.String filename)
Reads the whole input stream into a byte array |
static byte[] |
readBytesFromStream(java.io.InputStream is)
Reads the whole input stream into a byte array |
static java.lang.String |
readString(java.io.Reader reader)
|
static java.lang.String |
readStringFromFile(java.io.File file)
Reads the whole file into a string |
static java.lang.String |
readStringFromFile(java.io.File file,
java.lang.String encoding)
Reads the whole file into a string |
static java.lang.String |
readStringFromFile(java.lang.String filename)
Reads the whole file into a string |
static java.lang.String |
relPath(java.lang.String dir,
java.lang.String path)
Calculates relative path |
static boolean |
setLastModified(java.io.File file,
long time)
Sets the last-modified time of the file or directory named by this abstract pathname. |
static java.lang.String[] |
splitPath(java.lang.String path)
Splits a path into directory name and file name |
static boolean |
synchronize(java.io.File left,
java.io.File right)
synchronizes two directories |
static boolean |
synchronize(java.io.File left,
java.io.File right,
java.lang.String what)
synchronizes two directories, left/what and right/what |
static java.lang.Iterable<java.io.File> |
tree(java.io.File folder)
Returns an Iterable<File> that scans, recursively, through the directory structure. |
static java.lang.Iterable<java.io.File> |
tree(java.io.File folder,
java.io.FileFilter filter)
Returns an Iterable<File> that scans, recursively, through the directory structure. |
static java.lang.Iterable<java.io.File> |
treePostorder(java.io.File folder)
Returns an Iterable<File> that scans, recursively, through the directory structure. |
static boolean |
unzip(java.util.zip.ZipInputStream zis,
java.io.File location)
unzips an input stream to a specified folder |
static java.io.File |
writeBytesToFile(byte[] data,
java.lang.String fileTo)
Writes bytes to a file |
static java.io.File |
writeToFile(byte[] data,
java.lang.String fileTo)
Creates a file and writes bytes into it |
static java.io.File |
writeToFile(char[] data,
java.lang.String fileTo)
Creates a file and writes chars into it |
static java.io.File |
writeToFile(java.lang.CharSequence data,
java.lang.String fileTo)
Creates a file and writes a char sequence into it |
static java.io.File |
writeToFile(java.io.InputStream is,
java.lang.String fileTo)
Creates a file and copies into it bytes from an input stream |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int FIND_FILE
public static final int FIND_DIRECTORY
public static final int FIND_ALL
public static java.io.FileFilter DIRECTORY_FILTER
public static java.io.FileFilter fileFilter
public static boolean USE_NIO
Constructor Detail |
---|
public Files()
Method Detail |
---|
public static final java.lang.String getFullPath(java.io.File file)
file
-
public static final java.lang.String getFullPath(java.lang.String path)
path
-
public static java.lang.String relPath(java.lang.String dir, java.lang.String path)
dir
- directory path that is expected to start the file pathpath
- file path, relativer or not
relPath("c:\\MyHome\\dev", "c:\\MyHome\\dev\\src\\java")
returns "src\\java";relPath("/home/zaphod", "/home/zaphod/jbuilder8/samples/welcome")
returns "jbuilder8/samples/welcome";relPath("/home/zaphod", "/home/ford/jbuilder8")
returns "/home/ford/jbuilder8".public static java.lang.String path(java.lang.String currentDir, java.lang.String filepath)
currentDir
- directory pathfilepath
- file path, relative or not
path("c:\\MyHome\\dev", "src\\java")
returns "c:\\MyHome\\dev\\src\\java";path("/root/inetd", "/home/zaphod/jbuilder8/samples/welcome")
returns "/home/zaphod/jbuilder8/samples/welcome";path("\\Program Files", "c:\\MyHome\\dev")
returns "c:\\MyHome\\dev".public static java.lang.String[] splitPath(java.lang.String path)
path
-
splitPath("/home/zaphod/jbuilder8/samples/welcome")
returns {"/home/zaphod/jbuilder8/samples", "welcome"};splitPath("src.java")
returns {".", "src.java"};splitPath("MyHome\\dev")
returns {"MyHome", "dev"}.public static java.lang.String dirname(java.io.File file)
file
-
dirname(new File("/home/zaphod/jbuilder11/samples/welcome"))
returns "/home/zaphod/jbuilder8/samples";dirname(new File("src.java"))
returns ".";dirname(new File("MyHome\\dev"))
returns "MyHome".public static java.lang.String dirname(java.lang.String path)
path
-
dirname("/home/zaphod/jbuilder11/samples/welcome")
returns "/home/zaphod/jbuilder8/samples";dirname("src.java")
returns ".";dirname("MyHome\\dev")
returns "MyHome".public static java.lang.String filename(java.lang.String path)
path
-
filename("/home/zaphod/jbuilder11/samples/welcome")
returns "welcome".public static java.util.List<java.lang.String> find(java.io.File subdir, java.util.regex.Pattern pattern)
subdir
- where to lookpattern
- to match
find(new File("."), Pattern.compile(".*les\\.java$")))
returns
Arrays.asList(new String[] {new File("Files.java").getCanonicalPath()}).public static java.util.List<java.lang.String> find(java.lang.String subdir, java.util.regex.Pattern pattern)
subdir
- where to lookpattern
- to match
find(".", Pattern.compile(".*les\\.java$")))
returns
Arrays.asList(new String[] {"Files.java"}).public static java.util.List<java.lang.String> find(java.lang.String subdir, java.lang.String pattern)
subdir
- where to lookpattern
- to match
find(".", ".*les\\.java$")
returns
Arrays.asList(new String[] {"Files.java"}).public static java.lang.String findLatest(java.lang.String subdir, java.lang.String pattern, int whatExactly)
subdir
- where to lookpattern
- to matchwhatExactly
- can be FIND_FILE or FIND_DIRECTORY or FIND_ALL
public static java.lang.String findLatest(java.lang.String subdir, java.lang.String pattern)
subdir
- where to lookpattern
- to match
public static java.lang.String findLatestFile(java.lang.String subdir, java.lang.String pattern)
subdir
- where to lookpattern
- to match
public static java.lang.String findLatestDirectory(java.lang.String subdir, java.lang.String pattern)
subdir
- where to lookpattern
- to match
public static final java.io.File[] listSubdirectories(java.io.File dir)
dir
- directory name
public static final java.io.File[] listFiles(java.io.File dir)
dir
- directory name
public static final java.lang.String lastModified(java.io.File file)
file
-
lastModified(new File("src/com/javatools/util/Objects.java"))
returns
"something".public static java.lang.String getcwd()
public static boolean deleteFile(java.lang.String filename)
filename
-
deleteFile("/etc")
returns true if the program runs as root.public static boolean deleteFile(java.io.File file)
file
- to delete
public static java.io.FileOutputStream makeFile(java.lang.String dirname, java.lang.String filename, boolean append) throws java.io.IOException
append
is true.
append
determines whether to open in append mode
dirname
- file locationfilename
- the name of the fileappend
- true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String dir, java.lang.String filename) throws java.io.IOException
dir
- file locationfilename
- the name of the file
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String[] path, boolean append) throws java.io.IOException
append
is true.
append
determines whether to open in append mode
path
- [0] is directory name, [1] is file nameappend
- true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String... path) throws java.io.IOException
path
- String[] - a compound file path, ending with file name
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String path, boolean append) throws java.io.IOException
append
is true.
append
determines whether to open in append mode
path
- file pathappend
- true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.lang.String path) throws java.io.IOException
path
- file path
java.io.IOException
public static java.io.FileOutputStream makeFile(java.io.File file, boolean append) throws java.io.IOException
append
is true.
append
determines whether to open in append mode
file
- the file to openappend
- true if open in append mode
java.io.IOException
public static java.io.FileOutputStream makeFile(java.io.File file) throws java.io.IOException
file
- the file to open
java.io.IOException
public static final java.io.OutputStreamWriter makeFileWriter(java.lang.String path, java.lang.String encoding) throws java.io.IOException
path
- the file to openencoding
- the encoding to use
java.io.IOException
public static final int adjustSizeByMooreLaw(int size, int thisYear)
size
- int original buffer sizethisYear
- int the year this specific size was chosen
public static final java.lang.String readString(java.io.Reader reader)
public static final java.lang.String readStringFromFile(java.io.File file)
file
- the file to read
readStringFromFile("../src/com/myjavatools/utils/Files.java")
returns a string starting with "/**\r\n * <p>Title: MyJavaTools: Files handling Tools</p>\r\n*".public static final java.lang.String readStringFromFile(java.io.File file, java.lang.String encoding)
file
- the file to readencoding
- the expected encoding
public static final java.lang.String readStringFromFile(java.lang.String filename)
filename
- the file to read
readStringFromFile("../src/com/myjavatools/utils/Files.java")
returns a string starting with "/**\r\n * <p>Title: MyJavaTools: Files handling Tools</p>\r\n*".public static final byte[] readBytesFromStream(java.io.InputStream is)
is
- input stream to read
readBytesFromStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}))
returns new byte[] {1, 2, 3, 4, 5}.public static final byte[] readBytesFromFile(java.lang.String filename)
filename
- file to read
readBytesFromFile("../src/com/myjavatools/utils/Files.java")
returns a byte array starting with {51, 50, 50, 13, 10, 32, 50}.public static final java.io.File writeToFile(java.lang.CharSequence data, java.lang.String fileTo)
data
- the char sequence to write to filefileTo
- file path
public static final java.io.File writeToFile(char[] data, java.lang.String fileTo)
data
- array of characters to write to filefileTo
- file path
public static final java.io.File writeToFile(byte[] data, java.lang.String fileTo)
data
- array of bytes to append to the end of filefileTo
- file path
public static final java.io.File writeBytesToFile(byte[] data, java.lang.String fileTo)
writeToFile(byte[],String)
public static final java.io.File writeToFile(java.io.InputStream is, java.lang.String fileTo) throws java.io.IOException
is
- input streamfileTo
- file path
java.io.IOException
public static final java.io.File appendToFile(java.lang.CharSequence data, java.lang.String fileTo)
data
- char sequence to append to the end of filefileTo
- file path
public static final java.io.File appendToFile(char[] data, java.lang.String fileTo)
data
- array of characters to append to the end of filefileTo
- file path
public static final java.io.File appendToFile(byte[] data, java.lang.String fileTo)
data
- array of characters to append to the end of filefileTo
- file path
public static final java.io.File appendBytesToFile(char[] data, java.lang.String fileTo)
data
- chars to append are converted to bytesfileTo
-
public static final java.io.File appendBytesToFile(byte[] data, java.lang.String fileTo)
appendToFile(byte[],String)
public static final java.lang.String getPackageName(java.lang.String basePath, java.lang.String currentPath)
basePath
- the base path for code sourcecurrentPath
- the path of current directory
getPackageName("c:\\home\\myjavatools\\src", "c:\\home\\myjavatools\\src\\com\\myjavatools\\util")
returns "com.myjavatools.util".getPackageName("c:\\home\\myjavatools\\src\\java", "c:\\home\\myjavatools\\src\\com\\myjavatools\\util")
returns null.public static void pipe(java.io.InputStream in, java.io.OutputStream out, boolean isBlocking, Files.ByteFilter filter) throws java.io.IOException
in
- InputStream the source of dataout
- OutputStream where the output goes, filtered if filter is present, or unfiltered otherwiseisBlocking
- boolean whether input is blocking (in this case the maximum amount is read in one operation; for nonblocking in.available() determines how many bytes can be read)filter
- ByteFilter the filter that applies to data; can be null
java.io.IOException
- when input or output fails
see the test for examplespublic static void pipe(java.io.InputStream in, java.io.OutputStream out, boolean isBlocking) throws java.io.IOException
in
- InputStream the source of dataout
- OutputStream where the output goes, filtered if filter is present, or unfiltered otherwiseisBlocking
- boolean whether input is blocking (in this case the maximum amount is read in one operation; for nonblocking in.available() determines how many bytes can be read)
java.io.IOException
- when input or output fails
see the test for examplespublic static boolean pipe(java.io.Reader in, java.io.Writer out)
in
- Reader the source of dataout
- Writer where the output goes, filtered if filter is present, or unfiltered otherwise
public static boolean copy(java.lang.String from, java.lang.String to, java.lang.String what)
from
- directory from where to copyto
- directory where to copywhat
- what to copy (file or directory, recursively)
copy("c:\\home\\vlad\\dev", "c:\\home\\vlad\\rtm", "contents.xml")
public static boolean copy(java.io.File from, java.io.File to, java.lang.String what)
from
- directory from where to copyto
- directory where to copywhat
- what to copy (file or directory, recursively)
copy(new File(myHomeDir, "dev"), new File(myHomeDir, "rtm"), "contents.xml")
public static boolean copy(java.lang.String from, java.lang.String to)
from
- to
-
copy("c:\\home\\vlad\\dev\\contents.xml", "c:\\home\\vlad\\rtm\\contents.rss")
public static boolean copy(java.io.File from, java.io.File to)
public static boolean setLastModified(java.io.File file, long time)
file
- Filetime
- long
true
if and only if the operation succeeded;
false
otherwise
java.lang.IllegalArgumentException
- If the argument is negative
java.lang.SecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String)
method denies write access to the named fileFile.setLastModified(long)
public static boolean equal(java.io.File left, java.io.File right)
left
- Fileright
- File
public static int compare(java.io.File left, java.io.File right) throws java.io.IOException
left
- right
-
copy(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss");
compare(new File(myHomeDir, "contents.xml"), new File(mySite, "contents.rss")
returns -1
java.io.IOException
public static boolean synchronize(java.io.File left, java.io.File right, java.lang.String what)
left/what
and right/what
left
- File first directory that contains directory whatright
- File second directory that contains directory whatwhat
- String name of directory which contents is being synchronized
- Returns:
- boolean true if success
Example:
synchronize(new File(myHomeDir), new File(mySite), "myjavatools.com")
will leave subdirectories named myjavatools.com
in these two directories absolutely identical.
public static boolean synchronize(java.io.File left, java.io.File right)
left
- File first directoryright
- File second directory
synchronize(new File(myHomeDir), new File(myBackupDir))
will leave the contents of directories myHomeDIr and myBackupDir absolutely identical.public static boolean unzip(java.util.zip.ZipInputStream zis, java.io.File location) throws java.io.IOException
zis
- ZipInputStream the source of zipped fileslocation
- File the folder (directory) where to unzip the files
unzip(Web.getUrlInputStream(new URL(synchronize(new File(myHomeDir), new File(myBackupDir))
will leave the contents of directories myHomeDIr and myBackupDir absolutely identical.java.io.IOException
- when something went wrongpublic static boolean install(java.lang.Class clazz, java.lang.String resourceArchiveName, java.io.File location) throws java.io.IOException
clazz
- Class the class whose package contains the archive as a resourceresourceArchiveName
- String the name of resource containing the archivelocation
- File directory where the archive is unzipped
java.io.IOException
- if something goes wrongpublic static boolean install(java.net.URL url, java.io.File location) throws java.io.IOException
URL
- url the url containing an archive to installlocation
- File directory where the archive is unzipped
java.io.IOException
- if something goes wrongpublic static boolean install(java.lang.String urlString, java.lang.String directoryName) throws java.io.IOException
String
- urlString the string with the url containing an archive to installlocation
- File directory where the archive is unzipped
java.io.IOException
- if something goes wrongpublic static boolean install(java.lang.Class clazz, java.lang.String resourceArchiveName, java.lang.String folderName) throws java.io.IOException
clazz
- Class the class whose package contains the archive as a resourceresourceArchiveName
- String the name of resource containing the archivefolderName
- String name of directory where the archive is unzipped
java.io.IOException
- if something goes wrongpublic static java.lang.Iterable<java.lang.Byte> bytes(java.io.InputStream is)
is
- InputStream the stream to scan
for(byte b : bytes(new java.net.URL("http://yahoo.com").openSream())) {
System.out.println(b);
}
public static java.lang.Iterable<java.lang.Byte> bytes(java.io.File file)
file
- File the file to scan
for(byte b : bytes(new File("notepad.exe"))) {
System.out.println(b);
}
public static java.lang.Iterable<java.lang.Character> chars(java.io.Reader reader)
reader
- Reader the reader to scan
for(char c : chars(new InputStreamReader(new java.net.URL("http://yahoo.com").openSream()))) {
System.out.println("[" + c + "]");
}
public static java.lang.Iterable<java.lang.Character> chars(java.io.File file)
file
- File the file to scan
for(char c : bytes(new File("readme.html"))) {
System.out.println("[" + c + "]");
}
public static java.lang.Iterable<java.lang.String> lines(java.io.Reader reader)
reader
- Reader the reader to scan
for(String line : chars(new LineNumberReader(new java.net.URL("http://yahoo.com").openSream()))) {
System.out.println(">" + line);
}
public static java.lang.Iterable<java.lang.String> lines(java.io.File file)
file
- File the file to scan
for(String line : lines(new File("readme.txt"))) {
System.out.println(">" + line);
}
public static java.lang.Iterable<java.io.File> tree(java.io.File folder)
folder
- File starting directory
for(File subfolder : tree(new File("."))) {
System.out.println(subfolder.getCanonicalPath());
}
for(File folder : tree(new File("."))) {
System.out.println(file.getCanonicalPath());
for (File file : files(folder)) {
System.out.println(" " + file.getName());
}
}
public static java.lang.Iterable<java.io.File> tree(java.io.File folder, java.io.FileFilter filter)
folder
- File starting directory
for(File subfolder : tree(new File("."))) {
System.out.println(subfolder.getCanonicalPath());
}
for(File folder : tree(new File("."))) {
System.out.println(file.getCanonicalPath());
for (File file : files(folder)) {
System.out.println(" " + file.getName());
}
}
public static java.lang.Iterable<java.io.File> treePostorder(java.io.File folder)
folder
- File starting directory
for(File subfolder : treePostorder(new File("."))) {
System.out.println(subfolder.getCanonicalPath());
}
for(File folder : treePostorder(new File("."))) {
System.out.println(file.getCanonicalPath());
for (File file : files(folder)) {
System.out.println(" " + file.getName());
}
}
public static java.lang.Iterable<java.io.File> files(java.io.File folder)
folder
- File directory to scan
for (File file : files(new File(".")) {
System.out.println(file.getName());
}
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |