output « API « Java I/O Q&A





1. Input and Output Stream Pipe in Java    stackoverflow.com

Does anyone have any good suggestions for creating a Pipe object in Java which is both an InputStream and and OutputStream since Java does not have multiple inheritance and both of ...

2. printf() functionality in Java combined with a CharBuffer or something like it    stackoverflow.com

I am a little confused here. I would like to do something like this:

  1. create some kind of buffer I can write into
  2. clear the buffer
  3. use a printf()-like function several times to append a ...

3. how to use a ByteBuffer with an OutputStream    stackoverflow.com

I need to put the contents of a java.nio.ByteBuffer into an java.io.OutputStream. (wish I had a Channel instead but I don't) What's the best way to do this? edit: and I can't ...

4. Java writeObject Vs. writeUTF    stackoverflow.com

What is faster?
out.writeObject(someString) or out.writeUTF(someString)

5. Java reading standard output from an external program using inputstream    stackoverflow.com

I am trying to develop a class that reads the standard output of an external program(using an instance of Process, Runtime.getRuntime().exec(cmdLine, env, dir)). The program takes user inputs during the process, and ...

6. Formatting a double output using BufferedWriter in Java    stackoverflow.com

I'm working on an assignment, and have completed the code, however I am having an issue with correct formatting of the output. I am taking a text file, separating the ...

7. What is InputStream & Output Stream? Why do we use them and when do we use each of them?    stackoverflow.com

It sounds like a very silly question but can anyone explain me about Input stream and output stream. I remain confused about when do we need input stream and when we need ...

8. platform-independent /dev/null output sink for Java    stackoverflow.com

Other than an anonymous class (new OutputStream() { ... }), can anyone suggest a moral equivalent of new FileOutputStream("/dev/null") that also works on Windows? In case someone's wondering 'what's this for?' I have ...

9. output as part of input stream    stackoverflow.com

Is there a way to output some text and allow a user to edit and submit as System.in? Obviously System.out.print is not editable... Eg. system outputs:

Hallo
user edits to:
Hello
system echos:
Hello





10. Streaming output with commons-exec?    stackoverflow.com

Can anyone give me an example of how to stream the output of an external program executed with DefaultExecutor? I'm not finding any documentation describing how to do this. My external process ...

11. Java's [Input|Output]Streams' one-method-call-for-each-byte: a performance problem?    stackoverflow.com

[Input|Output]Streams exist since JDK1.0, while their character-counterparts Readers|Writers exist since JDK1.1. Most concepts seem similar, with one exception: the base classes of streams declare an abstract method which processes one single byte ...

12. Write string to output stream    stackoverflow.com

I have several output listeners implementing OutputStream. It can be PrintStream writing to stdout or to a File, it can be writing to memory or any other output destination therefore I specified ...

13. Java Process getInputStream vs. getOutputStream    stackoverflow.com

I'm a bit confused about the streams... which is which? Simply, which stream should I use to catch the output of my Process, and which stream should I use to give my ...

14. "Turn off" the output stream    stackoverflow.com

I'm using a wayward library that, unfortunately, prints information to System.out (or occasionally System.err). What's the simplest way to prevent this? I've been thinking about creating an output stream to memory, replace ...

15. How to write to Standard Output using BufferedWriter    stackoverflow.com

I am currently writing an application that produces several log files using BufferedWriter. While debugging, however, I want to write to System.out instead of a file. I figured I ...

16. The difference between DataLine and (Output|Input)Stream?    stackoverflow.com

I am working on sound processing with the use of Java now. Within my project, I have to deal with the stream. So I have a lot of staffs to do ...





17. Resetting Standard output Stream    stackoverflow.com

I know that there is a function in Java to set Standard Output Stream to any user defined value using System.setOut method.. But is there any method to reset the standard output ...

18. Java Input and Output    stackoverflow.com

Explain the difference between the outputs of the following two fragments of code for outputting an int i to a file: i)

PrintWriter outfile = new PrintWriter(new FileWriter("ints.txt"));
outfile.print(i);
ii)
DataOutputStream out = new DataOutputStream(new FileOutputStream("ints.dat"));
out.writeInt(i);
I ...

19. reading from DataInputStream without knowing the output type     stackoverflow.com

Say i'm using DataInputStream to recieve data, but I don't know if I should use (for example) readUTF, readInt or readLong. Is there a method that tells me what type of ...

20. Java output from process buider overwritten when using BufferedReader    stackoverflow.com

I'm trying to run an external program in Java and to read the output. The program is a Linux application in C++ that runs a data mining algorithm and prints the ...

21. java - PrintWriter with FileWriter and BufferedWriter    stackoverflow.com

I'm at my wits end here. I'm trying to print a few thousands of lines in a file, using the following:

        BufferedWriter bw ...

22. How do you mock an output stream?    stackoverflow.com

By 'output steam' i mean any object which receives a sequence of bytes, or characters or whatever. So, java.io.OutputStream, but also java.io.Writer, javax.xml.stream.XMLStreamWriter's writeCharacters method, and so on. I'm writing mock-based tests ...

23. Trouble getting standard output in Java from a C program with getchar()    stackoverflow.com

I'm trying to call a C program from Java and capture the standard output. Here is my code:

try {
    ProcessBuilder pb = new ProcessBuilder("helloworld.exe");
    ...

24. Output control for HDMI out during live streaming in Java    stackoverflow.com

I am working on Android apps. I have to block HDMI Output during Live streaming when the device is connected to a non-HDCP compliant device. I have no idea how to find ...

25. Read a single file with multiple BufferedReaders    stackoverflow.com

I'm working on a program that needs to update a line that depends its value on the result of a line that goes read after. I thought that I could use ...

26. Accessing program messages output to error stream    stackoverflow.com

I've created a class which processes files and if it encounters certain specific errors, it outputs relevant error messages to the error stream. I am working on another class that needs ...

27. Output Stream in java    stackoverflow.com

Please explain out variable in System.out

out is sometimes referred to be object of type OutputStream sometimes referred to as object of type PrintStream
and even when it is ...

28. Way to close specific output streams    stackoverflow.com

Do you think this code close correctly the output stream entry ? Knowing that this is not the same type of output stream.

OutputStream out = new JarOutputStream(new FileInputstrem(fileName));
    ...

29. UTF-8 output of java program differs if compiled on command line vs. in IntelliJ    stackoverflow.com

The output of the following program differs depending on whether I have IntelliJ compile it, or whether I compile it by hand from the command line. As far as I ...

30. Stream writer on char[] does not work    stackoverflow.com

I have the following code, but the char[] cc does not seem to get written when I checked the output file. Can someone tell me what's wrong?

import java.io.*;

class Test {
 ...

31. java input output stream    stackoverflow.com

Does anyone have any good suggestions for creating a Pipe object in Java which is both an InputStream and and OutputStream since Java does not have multiple inheritance and both of ...

32. why can't see the output in dos window after using buffered reader..??    coderanch.com

I've a simple program which runs the Dos "dir" command through java. I can See the output in my java text area but when i run this program on the dos prompt it doesn't show anythin and i have to Cntrl-Alt-Del the programe. My code isimport java.io.*; public class toyshell2{ public static void main(String args[]) { try{ toyshell2 toy = new ...

33. return or output stream?    coderanch.com

i'm trying to find a way to return a string from 'streamgrabber'. without the return, it works fine and prints out the string returned from 'hashit.pl' which is a perl script/program (i'm always confused about the difference). why can't i return a variable? do i need to return a buffered output stream? what's the best way? all help is appreciated. [still ...

34. stream output to reader input?    coderanch.com

IOers, I am correct in stating that a Reader reads 1 byte at a time? I tought it read by default 1 unicode (16 bit) char at a time. I wrote the following very simple test program to write (using a stream) a byte followed by 3 chars. When I read these using a reader it seems to read one byte ...

35. Output stream: int read() AND write(int)! Why int?    coderanch.com

No, it's a good question, I think. For InputStream there's the fact that we need to be able to return a special value to indicate an end of stream. So all possible byte vaues are mapped to the 0-255 range, and -1 is used to indicate end of stream - meaning we need more than 256 values, and the return type ...

36. No output written to a file using FileWriter    coderanch.com

Hello: FileWriter fw = new FileWriter("dnslookup.txt"); fw.write("apogent.com"); Can someone explain to me as to why the above 2 lines of codr don't work. What I mean by that is that nothing is written out to the file 'dnslookup.txt'. This is a very simple implmentation of a writer. What is it that I am missing out here in code, why does the ...

37. how to capture output in stream    coderanch.com

38. Recycling my piped streams for file output?    coderanch.com

Hey, I have a question regarding streams. Ive looked high and low on the net, and havent really solved it via this route so im posting. I have a system whereby I am saving all System.out + System.err messages to a console. This works fine. I.e. piOut = new PipedInputStream(); poOut = new PipedOutputStream(piOut); outputPrintStream = new PrintStream(poOut, true); System.setOut(outputPrintStream); I ...

39. File Output stream adding extra character while writing    coderanch.com

Hi, Program objective is to make an Xml and save it in File System over a n/w. For that i am using the following lines of code : public boolean xmlToFile(Document document, String pathAndNameWithExtension) { if(pathAndNameWithExtension == null) pathAndNameWithExtension = "file///XMLOutput.xml"; try { File file = new File(pathAndNameWithExtension); file.createNewFile(); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformar = tFactory.newTransformer(); DOMSource domSource = new ...

40. Quickie question about DataInput and Output Streams    coderanch.com

So, I have a simple client/server program that used to send a String across the open connection using writeUTF and readUTF. So everything was working fine where I could send multiple Strings and then they were printed out on the server side one by one. To my dismay, it turned out that I could not use the writeUTF, and instead am ...

41. writing process output stream (p.getOutputStream) to a file    coderanch.com

Hi i am calling a java process from my web UI. i am using runtime.exec to execute an external java program. i need to redirect the process output stream to a file. That means all the system.out and system.err should be written to a file. i dont how to redirect the p.getOutputStream() to a file. Here is the code which i ...

42. closing PrintWriter cuts output    coderanch.com

import java.io.*; import java.util.*; public class ClassFinder { public static void main(String[] args) throws IOException { // stuff try { FileOutputStream fos = new FileOutputStream("file.txt", true); try { for (int i = 0; i < files.length; i++) { Process process = Runtime.getRuntime().exec("cmd /c command); InputStream is = process.getInputStream(); StreamEater outputEater = new StreamEater(is, "", fos); outputEater.start(); if (process.waitFor() == 0) { ...

43. problem in output when using ObjectOutputStream .    coderanch.com

Hi ALL, I have one doubt. Here is My program ----------------------- import java.io.*; class Player { Player() { System.out.print("P"); } } class CardPlayer extends Player implements Serializable { CardPlayer() { System.out.print("C"); } public static void main(String[] args) { CardPlayer c1 = new CardPlayer(); try { FileOutputStream fos = new FileOutputStream("play.txt"); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(c1); os.close(); FileInputStream fis = new ...

44. Using an output stream to write an int to file    coderanch.com

I'm trying to create random numbers(which is working fine) but I need to get them to output to a file to be read later on. public static void generate()throws IOException{ BufferedWriter out = new BufferedWriter(new FileWriter("Output.txt")); Random rand = new Random(); int[] AArray = new int[200]; for(int i=0;i<=20;i++){ int r = rand.nextInt(1000); System.out.println(r); AArray[i]=r; } for(int i=0;i<=20;i++){ out.write(AArray[i]); } out.close(); } ...

46. stream output variables to specific positions in output file    coderanch.com

Hello, In a proprietary db editor I put in the following: output stream outstream to value(outfile) append. put stream outstream variable1 format "X(5)" at 1 variable2 format "X(5)" at 10 variable3 format "zz999999" at 20 etc. which allowed me to line up a variable to a position in the file. I cannot find any such similar Java example. I have ended ...

47. formatting output in printstream    coderanch.com

49. Not getting input or output to the Stream    coderanch.com

Making the cliche chat program. Am not getting input or output. Please help. I feel like a complete noob again. package com.lab.week5; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.Semaphore; public class ChatServer extends Thread { private static Semaphore socketSemaphore = new Semaphore(1); public ChatServer() { runServer(); } @SuppressWarnings({ "null" }) private void runServer() { ...

50. Mark the current position in Output Stream    coderanch.com

There isn't anything like that in the API. However, you can always write it yourself. Here is one approach - extend FilterOutputStream; that way your class will act as a wrapper around any other OutputStream. - keep a buffer of bytes written to your stream but not to the wrapped OutputStream. - when calling flush() you clear the buffer and write ...

51. writing printwriter output to file    coderanch.com

How to write the printwriter output in the code below to a file.I am new to java. Please help me thanks in advance public void formatTx(DsTransaction tx, DsMetaData dbMeta, PrintWriter out) { out.print("Transaction: " ); out.print("numOps=\'" + tx.getSize() + "\' " ); out.println("ts=\'" + tx.getStartTxTimeAsString() + "\'"); for(DsOperation op: tx.getOperations()) { TableName currTable = op.getTableName(); TableMetaData tMeta = dbMeta.getTableMetaData(currTable); String opType ...

52. output stream to input stream    coderanch.com

Well, it depends on requirement. Here is my business case.. I am working with Apache FOP where JAXB annoted java beans are used to generate PDF documents. Here are two steps. 1) JAXB marchaller converts bean to XML output stream. I dont want to write to a file. 2) Above output stream needs to go in as inout to FOP transformer. ...

54. Pausing the output stream?    forums.oracle.com

Ahh! Sorry bout that... stupid friend. Anyway. I have a question. Is there a way to pause the output in a series of System.out.println commands? Like I'm making a game with a friend and its all text based using the java console and... It would be very confusing if all this text popped up at once! Something like... System.out.println("Hello!") //pauses System.out.println("Nice ...

55. Can I read from an output stream?    forums.oracle.com

Is that even possible? I have the super class to all byte output streams, um...output stream, is it possible to read from it (not write, that parts working fine), I know this is a little weird and unusaul but, can it be done? Thanks for any help! And no I don't want a byte to character conversion (the byte data will ...

56. Reading an output Stream    forums.oracle.com

I changed the strings to be equal to "" and now I get nothing kicked back. If I put perfect information in the text boxes and hit the execute command the command works flawlessly. But if I put something screwy in the text boxes it just stares at me and outputs nothing. If I run the same command from the command ...

57. NNTP Input stream / File output stream help    forums.oracle.com

My original battle was that a BufferedReader and FileWriter caused the downloaded file to fail a crc check. After investigation (comparison to a correctly downloaded file) I found that wherever the correct version had a (int) value of 65533 my downloaded file had a (int) value of 63. I came to the conclusion this has something to do with the default ...

58. Fileinput and output stream    forums.oracle.com

ahhhh great scott. errr i hate this programming and i love it also i guess drinking beer and programming is a bad idea lol. That was the problem paul i had that print.close() inside the while loop omg how can i do that Thanks alot a bunch paul and no the compiler did not give me any IO exception also. if ...

59. Java - InputStream - Weird Characters in the Output!    forums.oracle.com

Hi, I have a software which outputs lines of numbers one by one. In another java program, I use BufferedReader as follows: BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"US-ASCII")); where pr is the process which runs the software. For each line in the output stream, I try to check whether the first number in the line is greater than a certain value ...

60. Cannot read from an Output stream of a process    forums.oracle.com

I believe that ssh is one of those unix commands that is specifically written to be run only in terminal mode. You're probably better off just getting a java ssh library. Otherwise, I'd suggest the following: 1. Try some other command in the same Java code. If it works, it's an ssh-specific issue. If it fails in the same way, there's ...

62. input&output stream    forums.oracle.com

Hi! I've got InputStream and OutputStream (from 2 sockets, but that's not important). And I want to "connect" Input + Output Stream, so when I read something from Input, I will write it to Output one solution can be to use buffer, but i hope, there is some other way... thanks a lot

63. Input stream to output stream    forums.oracle.com

What????? What is it, exactly, that you want to do? Do you want to write to the file you just read from? If so close the InputStream and open an OutputStream. Other Input to Output scenarios are likely to run analog to this one, so answer the question and maybe you can be helped.

64. writing printwriter output to file    forums.oracle.com

How to write the printwriter output in the code below to a file.I am new to java. Please help me thanks in advance public void formatTx(DsTransaction tx, DsMetaData dbMeta, PrintWriter out) { out.print("Transaction: " ); out.print("numOps=\'" + tx.getSize() + "\' " ); out.println("ts=\'" + tx.getStartTxTimeAsString() + "\'"); for(DsOperation op: tx.getOperations()) { TableName currTable = op.getTableName(); TableMetaData tMeta = dbMeta.getTableMetaData(currTable); String opType ...