We use Azure File Share client library for Java – version 12.23.0 to access files stored in Azure File share.
code to create file
ShareFileClient srcFileClient = new ShareFileClientBuilder().connectionString(CONNECTION_STRING)
.endpoint(ENDPOINT).shareName(shareName).resourcePath(parentDirName + "/" + srcFileName)
.buildFileClient();
byte[] data = "Sample line 1n".getBytes(StandardCharsets.UTF_8);
ShareFileInfo clientInfo = srcFileClient.create(data.length);
InputStream uploadData = new ByteArrayInputStream(data);
try {
srcFileClient.upload(uploadData, data.length);
}
catch (ShareStorageException e) {
System.out.println("Failed to upload the data Reasons: " + e.getMessage());
}
Want to append file content and try out the following code
byte[] data = "Sample line 2".getBytes(StandardCharsets.UTF_8);
InputStream uploadData = new ByteArrayInputStream(data);
Response<ShareFileUploadInfo> response = srcFileClient.uploadRangeWithResponse(
new ShareFileUploadRangeOptions(uploadData, data.length), Duration.ofSeconds(30), null);
I am expecting following content for file
Sample line 1
Sample line 2
But It overwrites the first line and results in
Sample line 2
any suggestions for things to look to append content for existing file?