在java中怎么设置文件夹的属性
1个回答
展开全部
public File getParentFile()
{
String s = getParent();
if(s == null)
return null;
else
return new File(s, prefixLength);
}
public String getPath()
{
return path;
}
public boolean isAbsolute()
{
return fs.isAbsolute(this);
}
public String getAbsolutePath()
{
return fs.resolve(this);
}
public File getAbsoluteFile()
{
return new File(getAbsolutePath());
}
public String getCanonicalPath()
throws IOException
{
return fs.canonicalize(fs.resolve(this));
}
public File getCanonicalFile()
throws IOException
{
return new File(getCanonicalPath());
}
public URL toURL()
throws MalformedURLException
{
String s = getAbsolutePath();
if(separatorChar != '/')
s = s.replace(separatorChar, '/');
if(!s.startsWith("/"))
s = "/" + s;
if(!s.endsWith("/") && isDirectory())
s = s + "/";
return new URL("file", "", s);
}
public boolean canRead()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return fs.checkAccess(this, false);
}
public boolean canWrite()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkWrite(path);
return fs.checkAccess(this, true);
}
public boolean exists()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return (fs.getBooleanAttributes(this) & 0x1) != 0;
}
public boolean isDirectory()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return (fs.getBooleanAttributes(this) & 0x4) != 0;
}
public boolean isFile()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return (fs.getBooleanAttributes(this) & 0x2) != 0;
}
public boolean isHidden()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return (fs.getBooleanAttributes(this) & 0x8) != 0;
}
public long lastModified()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return fs.getLastModifiedTime(this);
}
public long length()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return fs.getLength(this);
}
public boolean createNewFile()
throws IOException
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkWrite(path);
return fs.createFileExclusively(path);
}
public boolean delete()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkDelete(path);
return fs.delete(this);
}
public void deleteOnExit()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkDelete(path);
fs.deleteOnExit(this);
}
public String[] list()
{
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkRead(path);
return fs.list(this);
}
public String[] list(FilenameFilter filenamefilter)
{
String as[] = list();
if(as == null || filenamefilter == null)
return as;
ArrayList arraylist = new ArrayList();
for(int i = 0; i < as.length; i++)
if(filenamefilter.accept(this, as[i]))
arraylist.add(as[i]);
return (String[])arraylist.toArray(new String[0]);
}
public File[] listFiles()
{
String as[] = list();
if(as == null)
return null;
int i = as.length;
File afile[] = new File[i];
for(int j = 0; j < i; j++)
afile[j] = new File(path, as[j]);
return afile;
}
public File[] listFiles(FilenameFilter filenamefilter)
{
String as[] = list();
if(as == null)
return null;
ArrayList arraylist = new ArrayList();
for(int i = 0; i < as.length; i++)
if(filenamefilter == null || filenamefilter.accept(this, as[i]))
arraylist.add(new File(path, as[i]));
return (File[])arraylist.toArray(new File[0]);
}
public File[] listFiles(FileFilter filefilter)
{
String as[] = list();
if(as == null)
return null;
ArrayList arraylist = new ArrayList();
for(int i = 0; i < as.length; i++)
{
File file = new File(path, as[i]);
if(filefilter == null || filefilter.accept(file))
arraylist.add(file);
}
return (File[])arraylist.toArray(new File[0]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询