Questions tagged [printstream]

175 questions
1
vote
1 answer

Get the charset of a PrintStream in Java

I know we can set the Charset of a PrintStream like this: PrintStream printStream = new PrintStream( System.out, true, StandardCharsets.UTF_8.name() ); // "UTF-8". Is there a way to get the Charset being used by a PrintStream object such as…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
1
vote
0 answers

PrintWriter not working, but PrintStream is

I'm trying to print some characters to an output file. If I do: PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.txt"))); out.println("Hi"); nothing happens. However, if I do: PrintStream out = new PrintStream(new…
esnoopy808
  • 27
  • 2
1
vote
4 answers

Why/when does System.out.println(); give error: method print(boolean)...not applicable

I recently learned that use of System.out.print(); results in this error: The method print(boolean) in the type PrintStream is not applicable for the arguments () I found this when helping somebody else with their coding. Of course the natural…
K. hervey
  • 119
  • 2
  • 13
1
vote
2 answers

Cannot print inside forEach loop in stream java

The method "combination" should make combination of input arrays. And I like to get this stream of combination and save it into a file. public void writeDot() { try (PrintStream out = new PrintStream(path, "UTF-8")) { out.print("digraph…
Hannah Lee
  • 383
  • 2
  • 7
  • 19
1
vote
2 answers

How toString() overriding works

I just learnt about the toString() method in object class and how to override it in other class. class Box { public String toString(){ return "class Box"; } } class B { public static void main(String args[]){ Box…
R. S. D
  • 33
  • 4
1
vote
0 answers

Android: PrintStream.println(String) to .txt file contains <0x00> in java

I am trying to write some data to txt file using PrintStream.println. Some times it is working fine, But some times it is crashing the application. When i saw the result file, It contains <0x00> very huge amount of time. After that nothing printed…
user3619128
  • 285
  • 1
  • 5
  • 12
1
vote
1 answer

How to use PrintStream to write to a text file without leaving any blank line between each row?

I'm doing a phone book project for my school homework assignment. What I have to do is to store information of each person into a text file and read it every time the program runs. However, every time it stores the information into the text file, it…
Hung Do
  • 63
  • 1
  • 9
1
vote
0 answers

println() with Printwriter object not writing to a file

Why is PrintWriter not writing to the file in the following code? import java.io.*; import java.util.*; class test{ public static void main(String[] args) throws IOException{ Scanner in = new Scanner(System.in); …
lynxx
  • 544
  • 3
  • 18
1
vote
2 answers

How to convert console data to text file in Java

I'm trying to export my console output to the text file. This output also comes from the serial port. But, I couldn't do it, it prints only one line. Can anyone help me? The code that I wrote is below. String input = new String(buffer, 0, len);…
1
vote
2 answers

How do I instantiate a PrintStream that all methods can use, and will append to the same file?

I've been searching around for some time, and can't find a way to do this that I understand. The answers I get involve a few lines of code, and different printer objects (FileOutputStream, FileWriter, bufferedwriter, etc) The PrintStream ps is used…
Jo K
  • 17
  • 1
  • 5
1
vote
1 answer

Printstream input to a text file

// I'm searching for an Int in a text file, displaying that Int on console, creating a text file to print that Int. I get this instead of an Int: java.util.Scanner[delimiters=\p{javaWhitespace}+][position=666][match valid=true][need…
cscontrol
  • 73
  • 7
1
vote
1 answer

Unable to print Non English (Latvian) Characters from pdf file correctly in Java using PDFBox?

import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; import org.apache.pdfbox.text.PDFTextStripper; public class sample { public static…
1
vote
4 answers

printstream & printwriter

how come System.out.println() method prints character on the screen when out is of type print stream which is used to display bytes
rishabh
  • 11
  • 2
1
vote
0 answers

Rename file using scanners

I need to rename the file temp.txt later on in my code. I tried doing this with the newFile = new File(name); line, but this just created a new file entirely. Could you point me in the right direction here? public static File InputOutput (Scanner…
1
vote
1 answer

Java PrintStream redirection behaving unexpectedly

I was writing a basic server program when I used System.out.println to print out my log messages. I wrote a basic class file that uses that to write out to log. If I were to write the following: System.out.println("Hello,…
Garhoogin
  • 91
  • 2
  • 9