file與 byte[] 互轉

byte 轉fileget

String filepath="D:\\"+getName();
          File file=new File(filepath);
          if(file.exists()){
              file.delete();
          }
          FileOutputStream fos = new FileOutputStream(file);   
          fos.write(data,0,data,.length);   
          fos.flush();   
          fos.close();  input

 

file轉 byteit

FileInputStream inputStream = new FileInputStream(file);
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();  
        int ch;  
        while ((ch = inputStream.read()) != -1) {  
         bytestream.write(ch);  
        }  
        byte[] data= bytestream.toByteArray();  
        bytestream.close();  
        inputStream.close();    
        return data;test

相關文章
相關標籤/搜索