需要将图像加载到byte []变量。
File file = new File(context.getFilesDir(), body + ".image");
BufferedReader in = new BufferedReader(new FileReader(file));
如何将BufferedReader
转换为byte[]
?
答案 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});
};