Questions tagged [printstream]

175 questions
2
votes
1 answer

PrintStream not creating a file?

I get an error at line 58 which says the file isn't found, but shouldn't the PrintStream have created the file? (Note: No file is created at all.) Thanks! WhyDoINeedToAddMoreDetailIAlreadySaidWhatINeedToSay import java.io.*; import…
Locke
  • 33
  • 2
2
votes
2 answers

Java: Two threads communicating via streams is company, three's a crowd

In this code segment, I create a pipe and attach a Scanner on one end and a PrintStream on the other in order to communicate between several consumer and producer threads. Then I create and start three threads: The first thread is a consumer…
David Stigant
  • 121
  • 1
  • 4
2
votes
3 answers

Write console output of numbers to text file

quick question, I don't know what I'm missing here. If I have a console output of 9 numbers in a row, and 9 total rows, how would I go about writing that exact output to an external text file, so it looks the same way in the text file. Assuming the…
user5560769
2
votes
3 answers

Default Classes imported in java

I have a simple code: public class Hello { public static void main(String[] args) { System.out.println("Hello World"); } } I know that Object class is imported by default in every java program, but I wanted to ask whether…
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
2
votes
1 answer

What is the best way, if possible, to send information from a Java PrintStream to a JTextPane?

In Java, I have a package that translates XML metadata from one standard to another. This package is ultimately accessed through a single function and sends all of its output through a PrintStream object. The output sent is just a status of each…
Daniel Reeves
  • 166
  • 1
  • 4
2
votes
2 answers

Java DataInputStream sometimes returns empty

I currently am making a messaging application which I will also add encryption to later. I have a server which opens a socket and waits for clients to connect. Once client connects, it creates a new thread for that client. and then waits for…
2
votes
2 answers

Java Socket OutputStream is not flushing

I am writing a socket-based server in java. A client connects to it(a web-browser) and the server sends back a simple html code and sets cookie to recognize next time client connects to it again. I am using PrintStream to write to the socket , but…
Farah
  • 29
  • 1
  • 3
2
votes
3 answers

Redirect lots of system.out.println's to a .txt file

Possible Duplicate: Print java output to a file In a Java program, I have a long method, (which I don't think is important to post since it's not vital to the question) that has a large number of println statements to print status updates to the…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
2
votes
2 answers

How to append an exception's StackTrace into a file in java?

In java, when we catch a exception, we usually can use printStackTrace() method to print the error information, and we can also use printStackTrace(PrintStream out) to direct those information to a file. But how can I append those information into…
Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
2
votes
1 answer

Java: PrintStream unexpectedly autoflushing

import java.io.PrintStream; import java.util.Scanner; public class OutputTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); PrintStream out = new PrintStream(System.out); …
Retsam
  • 30,909
  • 11
  • 68
  • 90
2
votes
1 answer

Write data from standard out to text file in java not working

I am new to java programming and have been trying for the longest time to get the following code to work but although the program runs fine I don't seem to be seeing any output in the text file I am redirecting the output to. If someone could please…
anonuser0428
  • 11,789
  • 22
  • 63
  • 86
2
votes
1 answer

Does a PrintWriter / PrintStream need to be flushed?

I'd like to use a PrintWriter or PrintStream to write formatted strings out to an outputstream (for which I have no control over the creation). However flushing the underlying OutputStream has a big performance hit. Does a PrintWriter / PrintStream…
Philip Couling
  • 13,581
  • 5
  • 53
  • 85
1
vote
1 answer

Print stream does not format all values to 2 decimal places, but only some of them for text file

I am asked to make a bank account java program. I have made it and the values in the regular print works, but when I use print stream for the text file, half of the values have been changed, but the other half have not been changed to two decimal…
Aortax
  • 23
  • 6
1
vote
1 answer

Why use Printwriter over PrintStream in Java for outputting human readable text

The java documentation says to use Printwriter over Printstream when dealing with text, but why is this so? I know Printwriter deals with character streams and Printstream deals with byte streams but their both bytes at the end of the day. And since…
sniperking
  • 17
  • 4
1
vote
1 answer

Problem writing data from PrintStream to "Console as Process" and not "console as System.out" in Java

in Java 8, windows 10, i have a text app, i want to open a console and write something there, first try is: String [] cmd = {"cmd.exe", "/c", "start"}; ProcessBuilder f = new ProcessBuilder(cmd); f.redirectErrorStream(true); Process…
Ddll
  • 85
  • 8
1 2
3
11 12