2014-04-02 33 views
0

如何使用Java 7使用fileinputstream检索和读取本地文件。类似这样但是对于本地文件。随着新的安全设置,我不能让它的工作Java 7使用文件输入流检索和读取本地文件

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()); 
} 
} 
+2

'返回新的FileInputStream(文件);'代替你的整个方法体呢? –

+0

@DavidWallace假设上下文从签名但不可信的WebStart应用运行。 /'java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault()。getPath(file))'是Java SE 7做事的方式。 –

+0

@ TomHawtin-tackline应用程序使用可信证书签名,此方法不起作用 – user3375061

回答

0

ExtendedService.openFile是用于打开文件的等价物。这提供了读/写访问权限。没有选择要求只读!

+0

你评论上面的工作。 Java 7现在使用Java.nio.file,就像你展示的那样...感谢java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault()。getPa th(file)) – user3375061