File. Java

1,012 views
921 views

Published on

File class. About File and FileFilter, FilenameFilter interfaces

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,012
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

File. Java

  1. 1. Язык Java Объект File java.io
  2. 2. File ● public static final char separatorChar ● public static final String separator ● public static final char pathSeparatorChar ● public static final String pathSeparator ● public File(String pathname) ● public File(String parent, String child) ● public File(File parent, String child) ● public File(URI uri) ● public String getName() ● public String getParent() ● public File getParentFile() ● public String getPath() ● public boolean isAbsolute() ● public String getAbsolutePath() ● public File getAbsoluteFile() ● public String getCanonicalPath() throws IOException ● public File getCanonicalFile() throws IOException
  3. 3. File (продолжение) ● public boolean canRead() ● public boolean canWrite() ● public boolean exists() ● public boolean isDirectory() ● public boolean isFile() ● public boolean isHidden() ● public long lastModified() ● public long length() ● public boolean createNewFile() throws IOException ● public boolean delete() ● public String[] list() ● public String[] list(FilenameFilter filter) ● public File[] listFiles() ● public File[] listFiles(FilenameFilter filter) ● public File[] listFiles(FileFilter filter) ● public boolean mkdir() ● public boolean mkdirs() ● public boolean renameTo(File dest)
  4. 4. File (продолжение) ● public boolean setReadOnly() ● public boolean setWritable(boolean writable, boolean ownerOnly) ● public boolean setWritable(boolean writable) ● public boolean setReadable(boolean readable, boolean ownerOnly) ● public boolean setReadable(boolean readable) ● public boolean setExecutable(boolean executable, boolean ownerOnly) ● public boolean setExecutable(boolean executable) ● public boolean canExecute() ● public long getTotalSpace() ● public long getFreeSpace() ● public long getUsableSpace() ● public static File createTempFile(String prefix, String suffix, File directory) ● public static File createTempFile(String prefix, String suffix) throws IOException
  5. 5. Пример использования ● private File f; private Date d; private File f1; public FileTestClass(String name, String name2) { f1=new File(name); d=new Date(f1.lastModified()); f=new File(name2); } public String[] outAllFiles() { File[] fs=f.listFiles(new MyFilter(d)); String[] ss=new String[fs.length]; for(int i=0;i<fs.length;++i) ss[i]=fs[i].getPath(); return ss; }
  6. 6. Интерфейс FileFilter ● public interface FileFilter{ boolean accept(File pathname); }
  7. 7. Пример использования ● public class MyFilter implements FileFilter{ private Date date; public MyFilter(Date date) { this.date=date; } public boolean accept(File pathname) { Date date1 = new Date(pathname.lastModified()); return (date.getTime()>=date1.getTime()); } }
  8. 8. Интерфейс FilanameFilter ● interface FilenameFilter { boolean accept(File dir, String name); }
  9. 9. Работа со временем ● class Date ● public Date(long date) ● class GregorianCalendar ● public GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) ● public final Date getTime() ● public final void setTime(Date date)
  10. 10. Конец Вопросы e-mail: a.bovanenko@gmail.com

×