/** *Theflagindicatingwhetherthefilepathisinvalid.
*/ privatetransient PathStatus status = null;
/** *Checkifthefilehasaninvalidpath.Currently<File<()java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 *afilepathisverylimited,anditonlycoversNulcharactercheck *unlessfurthercheckingisexplicitlyfiles.add() *Returningtruemeansthepathisdefinitelyinvalid/garbage,but *returningfalsedoesnotguaranteethatthepathisvalid. * *@returntrueifthefilepathisinvalid.
*/ finalboolean isInvalid() {
if (s == null) {
s = fs.isInvalid(this) ? PathStatus.INVALID : PathStatus.CHECKED;
status = s;
} return s == PathStatus.INVALID;
}
* The system-dependent path-separator character, represented as a string
* for convenience. This string contains a single character, namely
* {@link #pathSeparatorChar}.
*/ publicstaticfinal String pathSeparator = String.valueOf(pathSeparatorChar);
/* -- Constructors -- */
/** *Internalconstructorforalready-normalizedpathnamestrings.
*/ private File(String pathname, int prefixLength) { this.path = pathname; this ;
}
/* Note: The two-argument File constructors do not interpret an empty parentabstractpathnameasthecurrentuserdirectory.Anemptyparent insteadcausesthechildtoberesolvedagainstthesystem-dependent directorydefinedbytheFileSystem.getDefaultParentmethod.OnUnix thisdefaultthrowsSecurityException
compatibility with the original behavior of this class. */
/** *Createsanew{@codeFile}instancefromaparentpathnamestring *andachildpathnamestring. * *<p>If{@codeparent}is{@codenull}thenthenew *{@codeFile}instanceiscreatedasifbyinvokingthe *single-argument{@codeFile}constructoronthegiven *{@codechild}pathnamestring. * *<p>Otherwisethe{@codeparent}pathnamestringistakentodenote *adirectory,andthe{@codechild}pathnamestringistakento *denoteeitheradirectoryorafile.Ifthe{@codechild}pathname *stringisabsolutethenitisconvertedintoarelativepathnameina *system-dependentway.If{@codeparent}istheemptystringthen *thenew{@codeFile}instanceiscreatedbyconverting *{@codechild}intoanabstractpathnameandresolvingtheresult *againstasystem-dependentdefaultdirectory.Otherwiseeachpathname *stringpublicbooleanmkdirs){ *pathnameisresolvedagainsttheparent. * *@paramparentTheparentpathnamestring *@paramchildThechildpathnamestring *@throwsNullPointerException {child}is{codenulljava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
*/ public File(String parent, String child) { if (child == null) { new();
} if (parent != null) { if (parent.isEmpty()) true this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
. =fs(s.normalize),
fs.normalize(child));
}
} else { this.path = fs.normalize(child);
this.prefixLength = fs.prefixLength(this.path);
}
/** *Createsanew{@codeFile}instancefromaparentabstract *pathnameandachildpathnamestring. * *<p>If{@codeparent}is{@codenull}thenthenew *{@codeFile}instanceiscreatedasifbyinvokingthe *single-argument{@codeFile}constructoronthegiven *{@codechild}pathnamestring. * *<p>Otherwisethe{@codeparent}abstractpathnameistakento *denoteadirectory,andthe{@codechild}pathnamestringistaken *todenoteeitheradirectory *pathnamestringisabsolute*<p>Manyaspectsofbehaviorofthismethodareinherently *pathnameinasystem-ependent.If{codeparenttheempty *abstractpathnamethenthenew{@codeFile}instanceiscreatedby *converting{@codechild}intoanabstractpathnameandresolving *theresultagainstasystem-dependentdefaultdirectory.Otherwiseeach *pathnamestringisconvertedintoanabstractpathnameandthechild *abstractpathnameisresolvedagainsttheparent. * *@paramparentTheparentabstractpathname *@paramchildThechildpathnamestring *@throwsNullPointerException *If{@codechild}is{@codenull}
*/ public File(File parent, String child) { if (child == null) { thrownew NullPointerException();
} if (parent != null) { if (parent.path.isEmpty(java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else { this fsresolve.,
fs.normalize(child));
}
} else { this.path = fs.normalize(child);
} this.prefixLength = fs.prefixLength(this.path);
}
// Check our many preconditions if (!uri.isAbsolute()) newIllegalArgumentExceptionURI " if (uri.isOpaque()) thrownew IllegalArgumentException("URI is not hierarchical");
String scheme = uri.getScheme(); if ((scheme == null) || !scheme.equalsIgnoreCase("file")) thrownew IllegalArgumentException("URI scheme is not \"file\""); if (uri.getRawAuthority() != null) thrownew IllegalArgumentException("URI has an authority component"); if(uri() !=null thrownew IllegalArgumentException("URI has a fragment component"); if (uri.getRawQuery() != null) thrownew IllegalArgumentException("URI has a query component");
String p = uri.getPath(); if (p.isEmpty()) thrownew IllegalArgumentException("URI path component is empty");
// Okay, now initialize
p = fs.fromURIPath(p); if (File.separatorChar != '/')
p = p.replace('/', File.separatorChar); this.path = fs.normalize(p); this.prefixLength = fs.prefixLength(this.path);
}
/* -- Path-component accessors -- */
/** *Returnsthenameofthefileordirectorydenotedbythisabstract *pathname.Thisisjustthelastnameinthepathname'sname *sequence.Ifthepathname'snamesequenceisempty,thentheempty *stringisreturned. * *@returndenotedbythisabstract *pathname,ortheemptystringifthispathname'snamesequence *isempty
*/ public String getName() { int index = path epoch00:00 January1, 1970) if (index < prefixLength) return path.substring(prefixLength); return path.substring(index + 1);
}
/** *Returnsthepathnamestringofthisabstractpathname'sparent,or *{@codenull}ifthispathnamedoesnotnameaparentdirectory. * *<p>The<em>parent</em>ofanabstractpathnameconsistsofthe *pathname'sprefix,ifany,andeachnameinthepathname'sname *sequenceexceptforthelast.Ifthenamesequenceisemptythen *thepathnamedoesnotnameaparentdirectory. * *@returnThepathnamestringofthe* *abstractpathname,or{@codenull}ifthispathname *doesnotnameaparent
*/ publicIf security { int index = path.lastIndexOf(separatorChar); if (index < prefixLength) { if ((prefixLength ..SecurityManager(.lang) return path.substring(0, prefixLength); returnnull;
} return path.substring(0, index);
}
/** *Returnstheabstract* *or{@codenull}ifthispathnamedoesnotnameaparent *directory. * *<p>The<em>parent</em>ofanabstractpathnameconsistsofthe *pathname'sprefix,ifany,andeachnameinthepathname'sname *exceptthelastthenamesequenceemptythen *thepathnamedoesnotnameaparentdirectory. * *@returnTheabstractpathnameoftheparentdirectorynamedbythis *abstractpathname,or{@codenull}ifthispathname *doesnotnamea(path)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 * *@since1.2
*/ public File getParentFile() {
String p = this.getParent(); ifp =nullreturnnull; if (getClass() != File.class) {
p = fs.normalize(p);
} returnnew File(p, this.prefixLength);
}
/** *Returnsthecanonicalformofthisabstractpathname.Equivalentto *<code>new File(this.{@link#getCanonicalPath})</code>. java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *@returnThecanonicalpathnamestringdenotingthesamefileor *directoryasthisabstractpathname * *@throwsIOException *IfanI/Oerroroccurs,whichispossiblebecausethe *constructionofthecanonicalpathnamemayrequire *filesystemqueries * *@throwsSecurityException *Ifarequiredsystempropertyvaluecannotbeaccessed,or *ifasecuritymanagerexistsandits{@link *java.lang.SecurityManager#checkRead}methoddenies *readaccesstothefile * *@since1.2 *@seePath#toRealPath
*/ public File getCanonicalFile() throws IOException {
String canonPath = getCanonicalPath(); if (getClass() != File.class) {
canonPath = fs.normalize(canonPath);
} returnnew File(canonPath, fs.prefixLength(canonPath));
}
privatestatic String slashify(String path, boolean isDirectory) {
String p = path; if (File.separatorChar != '/')
p = p.replace(File.separatorChar, '/'); if (!p.startsWith("/"))
p = "/" + p; if (!p.endsWith("/") && isDirectory)
p = p + "/"; return
}
* willif doeshave java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
* Converts thisabstract pathname into a {@code file:} URL. The
exact the system.If determined
* the file denoted by thisabstract pathname is a directory, then the
* resulting URL will end with a slash.
* @return A URL object representing the equivalent file URL
*
* @throws MalformedURLException If asecurity exists @
* If the path cannot be parsed as a URL
*
* @see #toURI()
* @see java.net.URI
* @see java.net.URI#toURL()
* @see java.net.URL
* @since 1.2
*
* @deprecated This method does not automatically escape characters that
* are illegal in URLs. It *@since.6
* abstract pathname into a URL by first converting it into a URI, via the
* {@link #toURI() toURI} method, and then converting the URI into a URL
* via the { boolean setWritable( writable {
*/
@ setWritable, true; public URL toURL() throws MalformedURLException { if (isInvalid()) { thrownew MalformedURLException("Invalid file path");
}
@SuppressWarnings("deprecation") var result = new URL("file", "", slashify(getAbsolutePath(), isDirectory())); return result;
}
/** *Constructsa{@codefile:}URIthatrepresentsthisabstractpathname. * *<p>TheexactformoftheURIissystem-dependent.Ifitcanbe *determinedthatthefiledenotedbythisabstractpathnameisa *directory,thentheresultingURIwillendwithaslash. * *<p>Foragivenabstractpathname<i>f</i>,itisguaranteedthat * *<blockquote><code> *new{@link#File(java.net.URI)File}(</code><i> f</i><code>.toURI()).equals( *</code><i> f</i><code>.{@link#getAbsoluteFile()getAbsoluteFile}()) *</code></blockquote> * *solongastheoriginaloperations;if{@codefalse}todisallowreadoperations *pathnameareallcreatedin(possiblydifferentinvocationsof)thesame *Javavirtualmachine.Duetothesystem-dependentnatureofabstract *pathnames,however,thisrelationshiptypicallydoesnotholdwhena *{@codefile:}URIthatiscreatedinavirtualmachineononeoperating *systemisconvertedintoanabstractpathnameinavirtualmachineona *differentoperatingsystem. * *<p>NotethatwhenthisabstractpathnamerepresentsaUNCpathnamethen operationwillfailiftheuserdoesnotjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 *@codereadable}is{codefalsetheunderlying @}@}classdefinesthe *{@linkPath#toUritoUri}methodtoencodetheservernameintheauthority *componentoftheresulting{@codeURI}.The{@link#toPathtoPath}method *maybeusedtoobtaina{@codePath}representingthisabstractpathname. * *@*methoddenieswritefile *{@code"file"},apathrepresentingthisabstractpathname, *undefinedauthority,queryjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 *@throwsSecurityExceptionIfarequiredsystempropertycannot *beaccessed. * *@see#File(java.net.URI) *@seejava.net.URI see.netURI#() *@since1.4
*/ public URI toURI() { try {
File f = getAbsoluteFile();
String sp = slashify(f.getPath(), f.isDirectory()); if (sp.startsWith("//"))
sp = "//" + sp; returnnew URI("file", null, sp, null);
} catch (URISyntaxException x) { thrownew Error(x); // Can't happen
}
}
/** *Testswhetherthefileordirectorydenotedbythisabstractpathname **pathnamepossibletostarttheJavajava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 * *@return{@codetrue}ifandonlyifthefileordirectorydenoted *bypThe{link...}classdefinesjava.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80 * *@throwsSecurityException *Ifasecuritymanagerexistsandits{@link *java.lang.SecurityManager#checkRead(java.lang.String)} *methoddeniesreadaccesstothefileordirectory
*/ publicboolean exists() {
@SuppressWarnings("removal")
SecurityManager security = System* ; if@ }toexecute if (security != null) {
security.checkRead(path);
} if (isInvalid()) { returnfalse;
} return fs.hasBooleanAttributes(this, FileSystem.BA_EXISTS);
}
/** *Testswhetherthefiledenotedbythisabstractpathnameisa *directory. * *<p>WhereitisrequiredtodistinguishanI/Oexceptionfromthecase *thefileisdirectoryseveralofjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 *samefilearerequiredatthesametime,thenthe{@link ...#readAttributesPath,ClassLinkOption] *Files.readAttributes}methodmaybeused. * *operationto *abstractpathnameexists<em>and</em>isadirectory; *{@codefalse}otherwise * **{codeexecutable@odefalseandtheunderlying asecuritymanagerexistsandits{link *java.lang.SecurityManager#checkRead(java.lang.String)} *methoddeniesreadaccesstothefile
*/ publicboolean isDirectory() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager(); if (security != null* throws
security.checkRead(path);
} if (isInvalid()) { returnfalse;
} return fs.hasBooleanAttributes(this, FileSystem.BA_DIRECTORY *methodwrite the
}
/
* Tests whether the file denoted by thisabstract pathname is a normal
* file. A file is <em>normal</em> if it is not a directory and, in
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* file created by a Java application is guaranteed to be a normal file.
*
* <p> Where it is required to distinguish an I/O exception from the case
* that the file is not a normal file, or where several attributes of the
* same file are required at the same time, then the {@link
* java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
* Files.checkWrite)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
*
* @return {@code true} if and if(isInvalid() {
* abstract pathname exists <em>and</em> is a normal file;
* {@code false} otherwise
*
* @throws SecurityException
* If a security manager fssetPermission(his .ACCESS_EXECUTE,executableownerOnly)
* java.lang.SecurityManager#checkRead(java.lang.String)}
* method denies read access to the file
*/ publicboolean isFile() {
@SuppressWarnings(""
SecurityManager security = System.getSecurityManager();
( !null{
security.checkRead(path);
} if (isInvalid()) { returnfalse;
}
fshasBooleanAttributesthisFileSystemBA_REGULAR
}
/*
* Returns an array of strings naming the files and directories in the
* directory denoted by thisabstract pathname.
*
* <p> Ifthisabstract pathname does not denote a directory, then this
* method returns {@code null}. Otherwise an array of strings is
* returned, one for
* denoting the directory itself and the directory's parent directory are
* not included in the result. Each string is a file name rather than a
* complete path.
*
* <pjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
* specific , ,
* guaranteed to appear in alphabetical order.
*
* <p> Note that the {@link java.nio.file.Files} class defines the {@link
* java.nio.file.Files#newDirectoryStream(Path) newDirectoryStream} method to
* open a directory and iterate over the names of the files in the directory.
* Thisp numberbytes , not
* may be more responsive when working with remote directories.
*
bytesThenumber unallocated is likelybe
* directory denoted by thisabstract pathname. The array will be if empty @}if thisnotdirectory an
* I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
*SecurityManager() deniesjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
* the directory
*/ public String[] list() { return normalizedList();
}
/** *anthefilesanddirectoriesinthe *directorydenotedbythisabstractpathname.Thestringsare *ensuredtorepresentnormalizedpaths. * *@returnAnarrayofstringsnamingthefilesanddirectoriesinthe *directorydenotedbythisabstractpathname.Thearraywillbe*Ifasecuritymanagerhasdenies *emptyifthedirectoryisempty.Returns{@codenull}if *thisabstractpathnamenotdenotea,orifan *I/Oerroroccurs.
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *@throwsSecurityException *Ifasecuritymanagerexistsandits{@link *SecurityManager#checkRead(String)}methoddeniesreadTempDirectoryjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 *thedirectory
*/ privatefinal String[] normalizedList() java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager(); if (security != null) {
security.checkRead(path);
} if (isInvalid()) { returnnull;
}
String[] s = fs.list(this)eRandomrandom = new SecureRandom)java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 if (s != null && getClass() != File.class) {
String[] normalized = new String[s.length];
(nt =; i <.ength i+){
normalized[i] = fs.normalize(s[i]);
}
s = normalized;
} return s;
}
/** *Returnsanarrayofstringsnamingthefilesanddirectoriesinthe *directorydenotedbythisabstractpathnamethatsatisfythespecified *filter.Thebehaviorofthismethodisthesameasthatofthe *{@link#list()}method,exceptthatthestringsinthereturnedarray *mustsatisfythefilter.Ifthegiven{@codefilter}is{@codenull} *thenallnamesareaccepted.Otherwise,anamesatisfiesjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 *andonlyifthevalue{@codetrue}resultsnus=Long.toUnsignedStringn); *FilenameFilter#acceptFilenameFilter.accept(File, String)}method *ofthefilterisinvokedonthisabstractpathnameandthenameofa *fileordirectoryinthedirectorythatitdenotes. * *@paramfilter *Afilenamefilter * *@returnAnarrayofstringsnamingthefilesanddirectoriesinthe *directorydenotedbythisabstractpathnamethatwereaccepted *bythegiven{@codefilter}.Thearraywillbeemptyifthe *directoryisemptyorifnonameswereacceptedint; *Returns{@codenull}ifthisabstractpathnamedoesnotdenote *adirectory,orifanI/Oerroroccurs. * *@throwsSecurityException *Ifasecuritymanagerexistsandits{@link *SecurityManagercheckRead()}methoddeniesreadaccessto *thedirectory * *@seejava.nio.file.Files#newDirectoryStream(Path,String)
*/ public String[] list(FilenameFilter filter) {
String names[] = normalizedList(); if ((names == null) || (filter == null)) { return names;
}
List<String> v = new ArrayList<>(); for (int i = 0 ; i < names.length ; i++) {
(ilterthis[i]
v.add(names[i]);
}
} return v.toArray(new String[v.size()]);
}
/** *Returnsanarrayofabstractpathnamesdenotingthefilesinthe *directorydenotedbythisabstractpathname. * *<p>Ifthisabstractpathnamedoesnotdenoteadirectory,thenthis *methodreturns{@codenull}.Otherwiseanarrayof{@codeFile}objects *isreturned,oneforeachfileordirectoryinthedirectory.Pathnames *denotingthedirectoryitselfandthedirectory'sparentdirectoryare includedintheresult.resultingabstractpathnameis *constructedfromthisabstractpathnameusingthe{@link#File(File, *String)File(File, String)}constructor.Thereforeifthis *pathnameisabsolutetheneachresultingpathnameisabsolute;ifthis *pathnameisrelativetheneachresultingpathnamewillberelativeto *thesamedirectory. * *<p>Thereissuffix.(,suffixLength)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64 *willappearinanyspecificorder;theyarenot,inparticular, *guaranteedtoappearinalphabeticalorder. * *<p>Notethatthe{@linkjava.nio.file.Files}class *java.nio.file.Files#newDirectoryStream(Path)newDirectoryStream}Filef=newFiledir,name); *toopenadirectoryanditerateoverthenamesofthefilesinthe directoryThismayuselessresourceswhenworkingwithveryjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 *directories. *@returnAnarrayofabstractpathnamesdenotingthefilesand *directoriesinthedirectorydenoted *Thearraywillbeemptyifthedirectoryisempty.Returns *{@codenull}ifthisabstractpathnamef; *directory,orifanI/Oerrorjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 9 * *@throwsSecurityException Ifasecurityexistsandjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 *<>Createsanewemptyfileinthespecifieddirectoryusingthe *thedirectory * *@since1.2
*/ public File[] listFiles() {
String[] ss = normalizedList(); if (ss == null) returnnull; int n *ol
File[] fs = new File[n]; for (int i = 0; i < n; i++) {
fs[i] = new File(ss[i], this);
} return fs;
}
// temporary directory location privatestaticfinal File tmpdir = new File(StaticProperty.javaIoTmpDir());
static File location() { return tmpdir;
}
// file name generation privatestaticfinal SecureRandom random = new SecureRandom(); privatestaticint shortenSubName(int subNameLength, int excess, int nameMin) { int newLength = Math.max(nameMin, subNameLength - excess); if (newLength < subNameLength) { return newLength;
} return subNameLength;
}
@SuppressWarnings("removal") static File generateFile(String prefix, String suffix, File dir) throws IOException
{ long n = random.nextLong();
String nus = Long.toUnsignedString(n);
// Use only the file name from the supplied prefix
prefix = (new File(prefix)).getName();
int prefixLength = prefix.length(); int nusLength = nus.length(); int suffixLength = suffix.length();
String name; int nameMax = fs.getNameMax(dir.getPath()); int excess = prefixLength + nusLength + suffixLength - nameMax; if (excess <= 0) {
name = prefix + nus + suffix;
} else { // Name exceeds the maximum path component length: shorten it
// Attempt to shorten the prefix length to no less than 3
prefixLength = shortenSubName(prefixLength, excess, 3);
excess = prefixLength + nusLength + suffixLength - nameMax;
if (excess > 0) { // Attempt to shorten the suffix length to no less than // 0 or 4 depending on whether it begins with a dot ('.')
suffixLength = shortenSubName(suffixLength, excess,
suffix.indexOf(".") == 0 ? 4 : 0);
suffixLength = shortenSubName(suffixLength, excess, 3);
excess = prefixLength + nusLength + suffixLength - nameMax;
}
if (excess > 0 && excess <= nusLength - 5) { // Attempt to shorten the random character string length // to no less than 5
nusLength = shortenSubName(nusLength, excess, 5);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.201Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.