位元組流
//讀檔案
@test
public void test()
} catch (ioexception e)
} catch (filenotfoundexception e)
}//寫檔案
@test
public void test2() catch (filenotfoundexception e)
} catch (ioexception e)
}//檔案的讀取和寫出
@test
public void filecopytest() throws filenotfoundexception, ioexception
outputstream.flush();
outputstream.close();
inputstream.close();
}}
//檔案讀寫的方法
/** * @return void
* @author zhangfu
* @description 檔案的拷貝
* @date 8:34 2018/10/29
* @param [srcpath, destpath]
*/public static void filecopy(file srcpath, file destpath) throws filenotfoundexception, ioexception
outputstream.flush();
outputstream.close();
inputstream.close();
}/**
* @author zhangfu
* @description 檔案的拷貝
* @date 9:10 2018/10/29
* @param [strpath, destpath]
* @return void
*/public static void filecopy(string strpath, string destpath) throws ioexception
字元流
@test
public void test() throws filenotfoundexception,ioexception
}@test
public void test2() throws filenotfoundexception,ioexception
@test
public void copyfile() throws filenotfoundexception,ioexception
writer.flush();
}@test
public void copyfilebuffer() throws filenotfoundexception,ioexception
writer.flush();
}
其他的流
@test
public void test()throws ioexception
//程式------>檔案
public static void outfile(byte bytes,string string) throws filenotfoundexception,ioexception
outputstream.flush();
outputstream.close();
inputstream.close();
}//程式-----> 檔案
public static void outfile(byte bytes,file file) throws filenotfoundexception,ioexception
outputstream.flush();
outputstream.close();
inputstream.close();
}//檔案----->程式(輸入)
public static byte getbytes(string string) throws filenotfoundexception,ioexception
bytes= bytearrayoutputstream.tobytearray();
bytearrayoutputstream.close();
inputstream.close();
return bytes;
}
編碼和解碼以及位元組流和字元流的轉換
@test
public void test()
@test
public void test2() catch (unsupportedencodingexception e)
system.out.println("亂碼的處理!!!!!!!!!!!!!!!!!!!!!!!");
try catch (unsupportedencodingexception e)
}@test
public void test3()
bw.flush();
bw.close();
br.close();
} catch (ioexception e)
}@test
public void test4()
bufferedwriter.flush();
} catch (ioexception e)
}
java IO流 位元組流讀寫中文
位元組流讀取中文的問題 位元組流在讀中文的時候有可能會讀到半個中文,造成亂碼 fileinputstream fis new fileinputstream yyy.txt byte arr new byte 4 int len while len fis.read arr 1 位元組流寫出中文的問...
字元流和位元組流
字元流和位元組流及其相關流的繼承關係 常用的方法 1.close 關閉流並釋放與之相關聯的任何系統資源 2.int read 讀取乙個字元並返回,沒有讀到返回 1 3.int read char cbuf 將字元讀入陣列,並返回讀取字元的個數,沒有讀到返回 1 4.int read char cbu...
字元流和位元組流
字元流和位元組流 位元組流兩個基類 inputstream outputstream 字元流兩個基類 reader writer 先學習一下字元流特點。既然io流是用於運算元據的。那麼資料的最常見體現形式是 檔案。那麼先以操作檔案為主來顯示。需求 在硬碟上,建立乙個檔案並寫入一些文字資料。找到乙個專...