Option 1: using stream to read in file, every time successful.
xmlfileChooser->launchAsync(
FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
[safeThis](const FileChooser &fc) mutable {
auto results = fc.getURLResults(); //an array of pointer to url, const Array< URL > &
//20201216 https://docs.juce.com/master/classURL.html
if (results.size() > 0) //return how many elements
{
auto url = results.getReference(
0); //url Returns a direct reference to one of the elements in the array,
//ScopedPointer<OutputStream> wo (url.createOutputStream()); //delete automatic
std::unique_ptr<InputStream> wi = url.createInputStream(false);
if (wi != nullptr) {
//auto text = wi->readEntireStreamAsString();
auto text = wi->readEntireStreamAsString();
DBG ("Original text = " + text);
}
Option 2: using File with string assignment constructor, with certain percentage, file open failure with no file exist or file size equal 0
URL urlprint =results.getReference(0);
if (urlprint.isEmpty())
{
DBG(“ulr is empty!!! return to avoid crash”);
return;
}
LOGD(“is this URL a file?: %d”, urlprint.isLocalFile());
DBG(urlprint.toString(0));
DBG(urlprint.getFileName()); // this works
DBG(urlprint.getParentURL().toString(0));
String tempfilename="/sdcard/Download/"+urlprint.getFileName();
DBG(tempfilename);
//20201217 check filechooser return file
//File tempfile = fc.getResult();
File tempfile = File(tempfilename);
Any help will be appreciated