BufferedReader到byte []

时间:2016-06-21 15:36:39

标签: android bufferedreader

需要将图像加载到byte []变量。

File file = new File(context.getFilesDir(), body + ".image");
BufferedReader in = new BufferedReader(new FileReader(file));

如何将BufferedReader转换为byte[]

1 个答案:

答案 0 :(得分:2)

Reader用于将字节转换为字符。这不是你想要的。您需要InputStream代替。然后,您可以根据需要从流read() byte[]File file = new File(context.getFilesDir(), body + ".image"); InputStream in = new BufferedInputStream(new FileInputStream(file)); byte[] buf = new byte[file.length()]; int numRead = in.read(buf); 数组,例如:

function arrayMail(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var startRow = 2;
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(startRow,1,lastRow,lastColumn);
var data = range.getValues();
var array = [];
for(var i=0;i<data.length;++i){
    var row = data[i];
    var rowTemp=[]; //create a blank array that will hold only the desired columns in this row
    for (var j=0; j<row.length; j++){    //iterates through columns
         if(j==4){continue;} 
         rowTemp.push(row[j]);         
        }    
    var emailPos = row[3];
    var date = row[2];   
      if(emailPos =='example1@gmail.com'&& date == -28){
      array.push(rowTemp);
      }
 }
var str = '';
var bodyEnd = '</table>';
var header = '<table border =1><tr><th>Message</th><th>Date Remind</th><th>Days Left</th><th>Email Address</th><th>Status</th></tr>';
for (var k = 0; k < array.length; k++) {
    str = str + '<tr>';
    for (var l = 0; l < array[k].length; l++) {
    str = str + '<td>' + array[k][l] + '</td>';
        }
    str = str + '</tr>';
var msg = header+str+bodyEnd;
}
GmailApp.sendEmail(Session.getActiveUser().getEmail(),'This is a test',msg,    {htmlBody:msg});
};