Class Files
- Author:
- tomyeh
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intOverwrites the destination file.static intPreserves the last modified time and other attributes if possible.static intSkips the SVN related files.static intCopy only when the source is newer or when the destination is missing.static final charThe separator representing the drive in a path. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidclose(InputStream strm) Close an input stream without throwing an exception.static final voidclose(OutputStream strm) Close an output stream without throwing an exception.static final voidClose a reader without throwing an exception.static final voidClose a writer without throwing an exception.static final voidCopies a file or a directory into another.static final voidcopy(File dst, InputStream in) Copies an input stream into a file (the original content, if any, are erased).static final voidCopies a reader into a file (the original content, if any, are erased).static final voidcopy(OutputStream out, InputStream in) Copies an input stream to a output stream.static final voidCopies a reader into a writer.static final StringcorrectSeparator(String flnm) Corrects the separator from '/' to the system dependent one.static final booleanDeletes all files under the specified path.static final StringLocates a file based o the current Locale.static final StringNormalizes the specified path.static final StringNormalizes the concatenation of two paths.static final byte[]readAll(InputStream in) Returns all bytes in the input stream, never null (but its length might zero).static final StringBufferReturns all characters in the reader, never null (but its length might zero).static final voidwrite(Writer out, StringBuffer sb) Writes the specified string buffer to the specified writer.
-
Field Details
-
DRIVE_SEPARATOR_CHAR
public static final char DRIVE_SEPARATOR_CHARThe separator representing the drive in a path. In Windows, it is ':', while 0 in other platforms. -
CP_PRESERVE
public static int CP_PRESERVEPreserves the last modified time and other attributes if possible.- See Also:
-
CP_UPDATE
public static int CP_UPDATECopy only when the source is newer or when the destination is missing.- See Also:
-
CP_OVERWRITE
public static int CP_OVERWRITEOverwrites the destination file.- See Also:
-
CP_SKIP_SVN
public static int CP_SKIP_SVNSkips the SVN related files.- Since:
- 5.0.0
-
-
Constructor Details
-
Files
protected Files()
-
-
Method Details
-
correctSeparator
Corrects the separator from '/' to the system dependent one. Note: always uses '/' even though Windows uses '\\'. -
readAll
Returns all bytes in the input stream, never null (but its length might zero).Notice: this method is memory hungry.
Notice: it doesn't close
in- Throws:
IOException
-
readAll
Returns all characters in the reader, never null (but its length might zero).Notice: this method is memory hungry.
- Throws:
IOException
-
copy
Copies a reader into a writer.Notice: it doesn't close
readerorwriter- Parameters:
writer- the destinationreader- the source- Throws:
IOException
-
copy
Copies an input stream to a output stream.Notice: it doesn't close
inorout- Parameters:
out- the destinationin- the source- Throws:
IOException
-
copy
Copies a reader into a file (the original content, if any, are erased). The source and destination files will be closed after copied.- Parameters:
dst- the destinationreader- the sourcecharset- the charset; null as default (ISO-8859-1).- Throws:
IOException
-
copy
Copies an input stream into a file (the original content, if any, are erased). The file will be closed after copied.- Parameters:
dst- the destinationin- the source- Throws:
IOException
-
copy
Copies a file or a directory into another.If neither
CP_UPDATEnorCP_OVERWRITE, IOException is thrown if the destination exists.- Parameters:
flags- any combination ofCP_UPDATE,CP_PRESERVE,CP_OVERWRITE.- Throws:
IOException
-
deleteAll
Deletes all files under the specified path. -
close
Close an input stream without throwing an exception. -
close
Close a reader without throwing an exception. -
close
Close an output stream without throwing an exception.- Since:
- 5.0.4
-
close
Close a writer without throwing an exception.- Since:
- 5.0.4
-
normalize
Normalizes the concatenation of two paths.- Parameters:
parentPath- the parent's pathchildPath- the child's path If it starts with "/", parentPath is ignored.- Since:
- 5.0.0
-
normalize
Normalizes the specified path. It removes consecutive slashes, ending slashes, redundant . and ...Unlike
File,normalize(java.lang.String, java.lang.String)always assumes the separator to be '/', and it cannot handle the device prefix (e.g., c:). However, it handles //.- Parameters:
path- the path to normalize. If null, an empty string is returned.- Since:
- 5.0.0
-
write
Writes the specified string buffer to the specified writer. Use this method instead of out.write(sb.toString()), if sb.length() is large.- Throws:
IOException- Since:
- 5.0.0
-
locate
Locates a file based o the current Locale. It never returns null.If the filename contains "*", it will be replaced with a proper Locale. For example, if the current Locale is zh_TW and the resource is named "ab*.cd", then it searches "ab_zh_TW.cd", "ab_zh.cd" and then "ab.cd", until any of them is found.
Note: "*" must be right before ".", or the last character. For example, "ab*.cd" and "ab*" are both correct, while "ab*cd" and "ab*\/cd" are ignored.
Unlike
Locators.locate(java.lang.String, java.util.Locale, org.zkoss.util.resource.Locator), the filename must contain '*', whileLocators.locate(java.lang.String, java.util.Locale, org.zkoss.util.resource.Locator)always tries to locate the file by inserting the locale before '.'. In other words, Files.locate("/a/b*.c") is similar to Locators.locate(("/a/b.c", null, a_file_locator);- Parameters:
flnm- the filename to locate. If it doesn't contain any '*', it is returned directly. If the file is not found, flnm is returned, too.- Since:
- 5.0.0
- See Also:
-