这是我第一次在项目中使用Java Spring启动,因为我主要使用C#,我需要从blob URL路径读取文件并将一些字符串数据(如密钥)附加到同一个文件中。在我的API下载文件之前流。
以下是我尝试过的方法:
//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路径中的某个文件并同时读取并下载相同的文件。
如果这里有更好的方法,请帮助我理解。
从逻辑的角度来看,您不会将数据附加到URL
的文件中。您需要创建新文件,写入一些数据,然后从URL
文件中追加内容。算法可能如下所示:
File
,也许在TMP
文件夹中。URL
下载文件并将其附加到磁盘上的文件中。一些好的文章可以从中开始: