尝试读取文本文件的内容时,我收到错误消息“java.lang.ClassCastException:org.openstack4j.openstack.common.DLPayloadEntity 与 java.io.File 不兼容”。
如何读取文本文件而不将其写入新文件?
我尝试使用 Apache Commons/IO 库的“readFiletoString()”方法将文件直接转换为字符串:
public String test() {
ObjectStorageDAO os;
List<String> containers = null;
String str = null;
try {
os = new ObjectStorageDAO(auth_url, userId, password, project, domainName);
// List the containers
containers = os.containers();
SwiftObject so = os.getObject("MyContainer", "message.txt");
File file = (File) so.download();
str = FileUtils.readFileToString(file, "UTF-8");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
str = e.toString();
}
return str;
}