我以 String 格式编码了一个文件名,并存储在一个表列文件中。现在用另一种方法我想将该文件下载到特定的本地路径。所以我正在解码保存在该路径中的文件,正在创建文件但文件中的内容丢失,这意味着正在创建空文件。
could you please help me to overcome this issue
try{
session=getSession();
ProjectsDO project = em.find(ProjectsDO.class, id);
//got the encode file from db
String encodedFile=project.getProjectFile();
// decoding the file to actual file
byte[] decodedBytes = Base64.getDecoder().decode(encodedFile);
String decodedString = new String(decodedBytes);
//saving the file to required path
FileOutputStream fout=new FileOutputStream("C:/Users/veerraju/Desktop/sap/projects/"+decodedString
);
System.out.println("file created succefully");
}catch(Exception e){
System.out.println(e.getMessage());
}
//this is the method used to encode only file name(that means it encodes"quote.jpg".
String originalInput = "C:/Users/veerraju/Desktop/sap/quote.jpg"; //cXVvdGUuanBn
File file=new File(originalInput);
String fileName=file.getName();
String encodedFile = Base64.getEncoder().encodeToString(fileName.getBytes());
杨魅力
相关分类