简体   繁体   English

如何从Java中的文件获取base64数据URI

[英]How to get the base64 data URI from a File in Java

I have a File object in Java, and I want to get the base64 URI of the file. 我在Java中有一个File对象,我想获取文件的base64 URI。 I am able to get the base64 itself like so: 我能够像这样获得base64本身:

  Base64.encodeBase64(FileUtils.readFileToByteArray(file)) 

However, this is not a URI; 但是,这不是URI。 does anybody know how I would get that instead? 有人知道我会怎么做吗? Thanks 谢谢

假设我了解您的问题,您可以像这样调用File.toURI()

Base64.encodeBase64(file.toURI())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM