ExtendedService.openFile
is the equivalent for opening a file. That gives read/write access. There is no option to ask for read-only!
Java 7 retrieve and read local file using fileinput stream
-
25-06-2023 - |
Question
How can i retrieve and read local file using fileinputstream using Java 7. Something like this but for a local file. With the new security settings, I cant get it to work
public static InputStream openReading(String file)
throws FileNotFoundException
{
try
{
PersistenceService pService = (PersistenceService) ServiceManager
.lookup(PersistenceService.class.getCanonicalName());
URL fileurl = new URL(getCode() + file);
FileContents fc= pService.get(fileurl);
fc.setMaxLength(10240000);
InputStream in= fc.getInputStream();
return stream;
}
catch (MalformedURLException m)
{
m.printStackTrace();
}
catch (FileNotFoundException f)
{
throw new FileNotFoundException(f.getMessage());
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow