使用javax.activation.DataHandler将文件转为byte[]

import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;
DataSource ds=new FileDataSource(new File("D:\\sicard\\blackBoard.txt"));
DataHandler dh=new DataHandler(ds);
byte[] b=new byte[dh.getInputStream().available()];
DataSource ds=new FileDataSource(new File("D:\\sicard\\blackBoard.txt"));
DataHandler dh=new DataHandler(ds);
byte[] b=new byte[dh.getInputStream().available()];
dh.getInputStream().read(b);


你可能感兴趣的:(File,import,byte)