这是我第一次在项目中使用Java Spring启动,因为我主要使用C#,我需要从blob URL路径读取文件并将一些字符串数据(如密钥)附加到同一个文件中。在我的API下载文件之前流。
以下是我尝试过的方法:
FileOutputStream / InputStream:抛出FileNotfoundException,因为它无法解析blob路径。
URLConnection:这让我到了某个地方,我能够成功下载文件但是当我在下载之前尝试写入/附加一些值时,我失败了。
我一直在做的代码。
//EXTERNAL_FILE_PATH is the azure storage path ending with for e.g. *.txt
URL urlPath = new URL(EXTERNAL_FILE_PATH);
URLConnection connection = urlPath.openConnection();
connection.setDoOutput(true); //I am doing this as I need to append some data and the docs mention to set this flag to true.
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("I have added this");
out.close();
//this is where the issues exists as the error throws saying it cannot read data as the output is set to true and it can only write and no read operation is allowed. So, I get a 405, Method not allowed...
inputStream = connection.getInputStream();
我不确定框架是否允许我修改URL路径中的某个文件并同时读取并下载相同的文件。
如果这里有更好的方法,请帮助我理解。