Closed ashokmurthy13 closed 3 years ago
I tried the below code, but still facing the issue.
Set<AccessMask> accessMask = new HashSet<>();
accessMask.add(AccessMask.FILE_WRITE_DATA);
Set<FileAttributes> fileAttributes = new HashSet<>();
fileAttributes.add(FileAttributes.FILE_ATTRIBUTE_NORMAL);
Set<SMB2CreateOptions> createOptions = new HashSet<>();
createOptions.add(SMB2CreateOptions.FILE_RANDOM_ACCESS);
File file = share.openFile("PATH", accessMask, fileAttributes, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN_IF, createOptions);
OutputStream os = file.getOutputStream(true);
try{
byte[] buffer = new byte[4096];
int length;
while((length = inputStream.read(buffer)) != -1){
os.write(buffer, 0, length);
}
}finally{
inputStream.close();
os.close();
file.close();
}
@hierynomus Can you please let me know if there is anything that I missed here?
I'm pretty sure that you can't just append data to the end of an excel file. This is a specific format that is binary. It's not a log or text file.
Append does work, for instance you can have a look at the integration test here:
@hierynomus yes I realized later that, I am writing the data in the same rows(from 0 to N) every time, during append it overwrites the existing data and the final file is corrupted.
Thanks for the reference file. I will look into it and update back on the results.
@ashokmurthy13 Can we close this issue?
@hierynomus yes we can close this. thank you.
Hi,
I need to append data to an existing file. Please find the code below I used. The InputStream which I am passing is an excel file.
When I execute the above code, I can see that the data append to the file, but when I open the file, it says corrupted or want to recover.
What am I doing wrong here? Can someone help me with this?