這里以位元組流FileInputStream,FileOutputStream為例。代碼例子如下:
importjava.io.File;
/**
*把一個文件夾中的文件復制到一個指定的文件夾
*@authoryoung
*
*/
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
publicclassCopyFile{
publicstaticvoidmain(String[]args){
/*指定源exe文件的存放路徑*/
Stringstr="f:/jdk-1_5_0_06-windows-i586-p.exe";
/*指定復制後的exe的目標路徑*/
Stringstrs="e:/.exe";
/*創建輸入和輸出流*/
FileInputStreamfis=null;
FileOutputStreamfos=null;
try{
/*將io流和文件關聯*/
fis=newFileInputStream(str);
fos=newFileOutputStream(strs);
byte[]buf=newbyte[1024*1024];
intlen;
while((len=fis.read(buf))!=-1){
fos.write(buf,0,len);
}
}catch(FileNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
fis.close();
fos.close();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}
② Java 怎麼才能讀取一個位元組里的每一位的2進制信息
這個非常早拿好簡單,
使用一個變數
test=1;
然後循環<<<左移8次陸鉛,
和你要檢查的位元組byte進行&操作,
如果結果敏巧是0 那麼這一位的2進制就是0,否則就是1。
一樓是培訓速成出來的吧,
連2進制都不知道。
杯具。