我需要将此 File 对象转换为字节数组:
File directory=new File(Environment.getExternalStorageDirectory() + "");
(我只需要 SD 卡上的文件夹和文件的名称。)
我已经尝试过这个:
byte[] send=null;
FileInputStream fis;
try {
fis = new FileInputStream(directory);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int readBytes = 0;
while(readBytes != -1)
{
readBytes = fis.read(buffer);
if(readBytes > 0)
{
bos.write(buffer, 0, readBytes);
}
else
break;
}
byte[] fileData = bos.toByteArray();
send=fileData;
但它返回此错误: java.io.FileNotFoundException: /mnt/sdcard (Is a directory)