outputstream

Capturing an c# executable output from another C# program

有些话、适合烂在心里 提交于 2019-12-18 08:54:54
问题 I am executing a C# program i.e a .exe from another C# program. but the .exe has some Console.WriteLine() in its program. I want to get the standard output into my C# program. for example, Consider a C# executable i.e 1.exe and there is another Program 2.cs. I am calling from 2.cs 1.exe. Now there is some output that the console is displaying from 1. exe. But I want the ouput in my program 2.cs. for displaying information to user. Is it possible? Please help Thanks Sai sindhu 回答1: You can use

Get Command Prompt Output to String In Java

跟風遠走 提交于 2019-12-18 04:12:47
问题 I need a java method that will read command prompt output and store it into a String to be read into Java. This is what I have so far but isn't working right. public void testGetOutput() { System.out.println("\n\n****This is the testGetOutput Method!****"); String s = null; String query = "dir " + this.desktop; try { Runtime runtime = Runtime.getRuntime(); InputStream input = runtime.exec("cmd /c " + query).getInputStream(); BufferedInputStream buffer = new BufferedInputStream(input);

Deserialize multiple Java Objects

放肆的年华 提交于 2019-12-17 19:39:52
问题 hello dear colleagues, I have a Garden class in which I serialize and deserialize multiple Plant class objects. The serializing is working but the deserializing is not working if a want to assign it to calling variable in the mein static method. public void searilizePlant(ArrayList<Plant> _plants) { try { FileOutputStream fileOut = new FileOutputStream(fileName); ObjectOutputStream out = new ObjectOutputStream(fileOut); for (int i = 0; i < _plants.size(); i++) { out.writeObject(_plants.get(i)

java.lang.IllegalStateException: Already using output stream [closed]

情到浓时终转凉″ 提交于 2019-12-17 19:09:31
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . windchill GUI on client side browser when a user clicks on a button particular pdf file should gets downloaded on his system.I have achieved this by using the following code. <body> <% String pdfname= session

Android: write failed: EPIPE (Broken pipe) Error on write file

馋奶兔 提交于 2019-12-17 18:51:38
问题 I was trying to take screenshot of the Android screen programatically. I had done the following code: private void getsnap(){ try{ Process sh = Runtime.getRuntime().exec("su", null, null); OutputStream os = sh.getOutputStream(); String filePath = this.getFilesDir().getPath().toString() + "/fileName1.jpeg"; os.write(("/system/bin/screencap -p " + filePath).getBytes("ASCII")); os.flush(); os.close(); sh.waitFor(); } catch (Exception e) { e.printStackTrace(); } } java.io.IOException: write

In a multithreaded Java program, does each thread have its own copy of System.out?

孤街浪徒 提交于 2019-12-17 16:34:03
问题 I'm writing a multithreaded Java program where each thread potentially needs its standard output redirected to a separate file. Each thread would have its own file. Is it possible to redirect System.out on a "per-thread" basis or are changes to System.out global across all threads? 回答1: Is it possible to redirect System.out on a "per-thread" basis No it is not possible. System.out is static and there is one per JVM that is loaded as part of the system classloader when the JVM initially boots.

Connecting an input stream to an outputstream

旧街凉风 提交于 2019-12-17 02:44:08
问题 update in java9: https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#transferTo-java.io.OutputStream- I saw some similar, but not-quite-what-i-need threads. I have a server, which will basically take input from a client, client A, and forward it, byte for byte, to another client, client B. I'd like to connect my inputstream of client A with my output stream of client B. Is that possible? What are ways to do that? Also, these clients are sending each other messages, which are

Proper way to close an AutoCloseable

巧了我就是萌 提交于 2019-12-17 02:32:14
问题 What is the most reliable pattern to follow when closing an OutputStream, ServerSocket, or other object that implements the AutoCloseable interface? Should I use try - catch - finally ? Or a shutdown hook. 回答1: The correct way to use an AutoCloseable instance is with a try-with-resources block, so the resource is reliably closed even if an exception is thrown. Like this: try (OutputStream stream = new ...) { ... // use the resource } catch (IOException e) { ... // exception handling code }

Java realtime writing file when it's opened

倾然丶 夕夏残阳落幕 提交于 2019-12-14 03:36:40
问题 I want to write data to file when it's opened, but it doesn't work. Calendar getTime works nice, System.out.println() proves this. Please, any idea, what's wrong...? Main class: public static void main(String[] args) throws IOException { // TODO code application logic here CurrentTime ct = new CurrentTime(); } CurrentTime class: public class CurrentTime { public OutputStream output; public InputStream input; public Process npp; CurrentTime() throws IOException { Timer t = new Timer(); npp =

Two streams and one file

本秂侑毒 提交于 2019-12-14 03:36:31
问题 What will happen if I create two instances of class FileInputStream and FileOutputStream using the default constructor and as an argument specify the same path and file name like this.. FileInputStream is = new FileInputStream("SomePath/file.txt"); FileOutputStream os = new FileOutputStream("SamePath/file.txt"); Let's imagine that we have a few strings inside the file "file.txt". Next, using a loop I am trying to read bytes from the file.txt and write them into the same file.txt each