Unable to read InputStream from Java Process (Runtime.getRuntime().exec() or ProcessBuilder)

I realize this is question is old, but I just experienced the same problem. In order to fix this I used this code.. List<String> commandAndParameters = …; File dir = …; // CWD for process ProcessBuilder builder = new ProcessBuilder(); builder.redirectErrorStream(true); // This is the important part builder.command(commandAndParameters); builder.directory(dir); Process process = builder.start(); InputStream is … Read more

How to convert InputStream to virtual File

Something like this should work. Note that for simplicity, I’ve used a Java 7 feature (try block with closeable resource), and IOUtils from Apache commons-io. If you can’t use those it’ll be a little longer, but the same idea. import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class StreamUtil { public static … Read more

Java Creating a new ObjectInputStream Blocks

Just to expand on FatGuy’s answer for other Googlers that find this; the solution to this “chicken and egg problem” is to have each side open the output stream first, flush the output stream, and then open the input stream. ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.flush(); ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

Java – How Can I Write My ArrayList to a file, and Read (load) that file to the original ArrayList?

You should use Java’s built in serialization mechanism. To use it, you need to do the following: Declare the Club class as implementing Serializable: public class Club implements Serializable { … } This tells the JVM that the class can be serialized to a stream. You don’t have to implement any method, since this is … Read more