开发者

access right to parse an XML in java

开发者 https://www.devze.com 2023-03-27 16:54 出处:网络
hello i have to execute this command: docRules = Docu开发者_开发百科mentBuilderFactory.newInstance()

hello i have to execute this command:

    docRules = Docu开发者_开发百科mentBuilderFactory.newInstance()
.newDocumentBuilder().parse( new File(IeplcDeployRules.clx));

When i try to create a parser i get the following error:

java.io.FileNotFoundException: /.../IeplcDeployRules.clx (Permission denied)

if i try manually to read the file it works but i cannot write in it because following are the permission.

-rwxr-xr-x 1 ieplcop ieplcdev  3424 Aug 11 17:16 IeplcDeployRules.clx

I do not want to change the permission since the file NEED only to be read from my Java application. I suppose there shold be therefore a way to specify that the file should be opened in read only mode.

I look the possible paramenter of File() parse() and .newDocumentBuilder() but none of them let me specify that the operation is read only!!

Any idea about how to procede?

Cheers, Ste


I do not know what the DocumentBuilder does internally, I would have to read its source. But you can use a different InputSource instead of a File, so that you have full control. For example a FileReader.

documentBuilder.parse(new InputSource(new FileReader(...));


You should pass an InputStream to the parse method instead of a File.

For example:

docRules = DocumentBuilderFactory.newInstance()
    .newDocumentBuilder().parse( new FileInputStream(new File("IeplcDeployRules.clx")));
0

精彩评论

暂无评论...
验证码 换一张
取 消