import .*;
/**
* 读取文件生成字节码
*/
public class FileUtils {
public static byte[] toByteArray(InputStream inputStream) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int n = 0;
while (-1 != (n = (buffer))){
(buffer,0,n);
}
return ();
}
public static void fileToBytes(byte[] bytes, String filePath, String fileName) throws IOException {
File file = new File(filePath + fileName);
//路径前面的文件夹不存在则会创建文件夹
if (!().exists()) {
().mkdirs();
}
try (
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos)) {
(bytes);
}
}
public static void main(String[] args) throws IOException {
File file = new File("/Users/ha/code/test/target/classes/s/");
try(
InputStream inputStream = new FileInputStream(file);
){
byte[] bytes = toByteArray(inputStream);
fileToBytes(bytes,"/Users/ha/code/test/testtarget/classes/","");
}
}
}