1. InputStream 和OutputStream
read():從流中讀入數據數組
skip():跳過流中若干字節數
available():返回流中可用字節數
mark():在流中標記一個位置
reset():返回標記過得位置
markSupport():是否支持標記和復位操做
close():關閉流
int read()
從輸入流中讀一個字節,造成一個0~255之間的整數返回(是一個抽象方法)。
int read(byte b[])l
讀多個字節到數組中。
int read(byte b[], int off, int len)
write(int b)
將一個整數輸出到流中(只輸出低位字節,抽象)
write(byte b[])
將字節數組中的數據輸出到流中
write(byte b[], int off, int len)
將數組b中從off指定的位置開始,長度爲len的數據輸出到流中
flush():刷空輸出流,並將緩衝區中的數據強制送出
close():關閉流
從輸入流中讀取長度爲len的數據,寫入數組b中從索引off開始的位置,並返回讀取得字節數。進行I/O操做時可能會產生I/O例外,屬於非運行時例外,應該在程序中處理。如:型FileNotFoundException, EOFException, IOException工具
2. 文件操做
File類
File類聲明以下:
public class File ectends Object implements Serializable,Comparable
構造方法:
public File(String pathname)
public File(File patent,String chile)
public File(String patent,String child)
文件名的處理
String getName( ); //獲得一個文件的名稱(不包括路徑)
String getPath( ); //獲得一個文件的路徑名
String getAbsolutePath( );//獲得一個文件的絕對路徑名
String getParent( ); //獲得一個文件的上一級目錄名
String renameTo(File newName); //將當前文件名改名爲給定文件的完整路徑
文件屬性測試
boolean exists( ); //測試當前File對象所指示的文件是否存在
boolean canWrite( );//測試當前文件是否可寫
boolean canRead( );//測試當前文件是否可讀
boolean isFile( ); //測試當前文件是不是文件(不是目錄)
boolean isDirectory( ); //測試當前文件是不是目錄
普通文件信息和工具
long lastModified( );//獲得文件最近一次修改的時間測試
字串1spa
long length( ); //獲得文件的長度,以字節爲單位
boolean delete( ); //刪除當前文件
目錄操做
boolean mkdir( ); //根據當前對象生成一個由該對象指定的路徑
String list( ); //列出當前目錄下的文件orm
3. 字符流對象
Reader類
• void close()
• void mark(int readAheadLimit)
• boolean markSupported() :
• int read()
• int read(char[] cbuf)
• int read(char[] cbuf, int off, int len)
• boolean ready()
• void reset()
• long skip(long n)
Writer類
• void close()
• void flush()
• void write(char[] cbuf)
• void write(char[] cbuf, int off, int len)索引
字串7
• void write(int c)
• void write(String str)
• void write(String str, int off, int len)ip
4. 若是你建立了一個文件對象,你可使用下面的方法來得到文件的相關信息,對文件進行操做。
1)文件名的操做
public String getName();返回文件對象名字符串,串空時返回null
public String toString();返回文件名字符串
public String getParent();返回文件對象父路徑字符串,不存在時返回null
public File getPath();轉換相對路徑名字符串
public String getAbsolutePath();返回絕對路徑名字符串,若是爲空返回當前使用目錄,也可使用系統指定目錄
public String getCanonicalPath()throws IOException;返回規範的路徑名串
public File getCanonicalFile()throws IOException;返回文件(含相對路徑名)規範形式
public File getAbsoluteFile();返回相對路徑的絕對路徑名字符串
public boolean renameTo(File dest);重命名指定的文件
public static Fiel createTempFile(String prifix,String suffix,File directory)throws IOException;在指定目錄創建指定先後綴空文件
public static Fiel createTempFile(String prifix,String suffix)throws IOException;在指定目錄創建指定先後綴文件
public boolean createNewFile()throws IOException;當指定文件不存在時,創建一個空文件
2)文件屬性測試
public boolean canRead();測試應用程序是否能讀指定的文件
public boolean canWrite();測試應用程序是否能修改指定的文件
public boolean exists();測試指定的文件是否存在
public boolean isDirectory();測試指定文件是不是目錄
public boolean isAbsolute();測試路徑名是否爲絕對路徑
public boolean isFile();測試指定的是不是通常文件
public boolean isHidden();測試只的是不是隱藏文件
3)通常文件信息和工具
public long lastModified();返回只的文件最後被修改的時間
public long length();返回指定文件的字節長度
public boolean delete();刪除指定的文件
public void deleteOnExit();當虛擬機執行結束時請求刪除指定的文件或目錄
4)目錄操做
public boolean mkdir();建立指定的目錄,正常創建時返回true,不然返回false
public boolean mkdirs();常見指定的目錄,包含任何不存在的父目錄
public String[]list();返回指定目錄下的文件(存入數組)
public String[]list(FilenameFilter filter);返回指定目錄下知足指定文件過濾器的文件
public File[]listFiels();返回指定目錄下的文件
public File[]listFiles(FilenameFilter filter);返回指定目錄下知足指定文件過濾器的文件
public File[]listFiles(FileFilter filter);返回指定目錄下知足指定文件過濾器的文件(返回路徑名應知足文件過濾器)
public static File[]listRoots();列出可用文件系統的根目錄結構
5)文件屬性設置
public boolean setLastModified(long time);設置指定文件或目錄的最後修改時間,操做成功返回true,不然返回false
public boolean setReadOnly();標記指定的文件或目錄爲只讀屬性,操做成功返回true,不然返回false
6)其餘
public URL toURL()throws MalformedURLException;把相對路徑名存入URL文件
public int compareTo(OBject o);與另外一個對性比較名字
public boolean equals(Object obj);與另外一個對象比較對象名
public int hashCode();返回文件名的哈希碼字符串