I want to implement GET api that returns ZIP file. I defined api using openapi As far as I understand my api should return byte[], so my controller looks like below Is it ok to return byte[] or it should be some stream, end user will get the zip? Implementation. I have map of objects that I am parsing using
Tag: java-io
How to sort files in a stream by partial filename?
I use the following to sort files first by name, then by modification date: Question: how can I refactor the File::getName part to only compare based on partial filename, like: StringUtils.substringBefore(file.getName(), “_”)? Answer You could replace the method reference with a lambda expression on the File object, although you’ll have to specify the types (see the additional discussion here):
How can I open a file in java without its contents been removed?
I want my program to create a file for the user (just for the first time) and write some information to it (it’s not just a line and also can be adjusted anytime later). So I did this: It works but there some problems: When the file gets opened later, as default, the File class removes its contents. When the
How to use environment variables in CMD using Java?
I am new to using the ProcessBuilder object to run commands inside of Java. My issue is that when I put my environment variables into the builder.command(…) method, it doesn’t work. However, when I …
How to display the contents of a .txt file on cmd window using Java?
I am working on a project and I want to display the contents of a .txt file on the CMD window. I wrote this piece of code to open a demo.txt file on cmd but it does not work. The “path” …
Reading output after Linux cmd execution is going to infinite loop
I am executing a cmd from jsch , once command is completed I need to show the command output. while reading the command output its taking long time and its ns not coming from the while loop even after execution of command. The following is my code: Answer I have added the exit command at the end of the command.
The Properties.load would close the InputStream?
I saw this example, and I didn’t see the close() method invoked on the InputStream, so would prop.load() close the stream automatically? Or is there a bug in the example? Answer The Stream is not closed after Properties.load () The above code returns “-1” so the stream is not closed. Otherwise it should have thrown java.io.IOException: Stream Closed
BufferedReader vs Console vs Scanner
Hi I’m new to Java and I would like to know what is the best choice to read a user Input in the console, as far as I know there are 3 ways to do it: Console console = System.console(); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); Scanner reader = new Scanner(System.in); Which one should I choose? Why that one and