I am creating a refill web service that accepts any file and saves it to the file system. To kill the request with the data, I am using the drop-downer to implement the service and postman / rest client. I'm not making a multipart (form-data) request.
Everything is working fine except for the saved file, the first letter is missing. My code is to call the service method and save it to the file system:
Input Request:
http: // localhost: 8080 / test / request / sample test
Sample.txt
Test content
Rest Controller
@PUT @Consumes (value = MediaType.WILDCARD) @Path ("/ test / request / {fileName}") Public Response Authentication Device (@PathParam ("fileName") string filename, @ContextHttpserve Request request request) IOException {... .... inputstream inputstream = request.getInputStream (); Type file (inputstream, filename); ......} Private Zero Write file (InputStream inputstream, string filename) {OutputStream OS = Faucet; {File file = new file (try this directory.); File.mkdirs (); If (file.exists ()) {os = New FileOutputStream (this.directory + fileName); Logger.info ("Writing the file successfully."); } Else {logger.info ("The problem creation directory .file can not be saved!"); } Byte [] buffer = new byte [inputstream.available ()]; Int n; While ((n = inputstream.read (buffer))! = -1) {os.write (buffer, 0, n); }} Hold (exception e) {logger.error ("Error writing to file:" + E); } Finally {try {os.close ()}; InputStream.close (); } Grip (IOException e) {logger.error (Error turning off input / output stream "" + E); }}}
In the output, the file is saved, but the character before the content is missing. Output file
Sample.txt:
this content
In the above output file, the character T is missing and it is for everyone File format
I do not know what I'm missing.
Please help me.
Thank you.
Comments
Post a Comment