Questions tagged [printwriter]

Java built-in class that prints formatted representations of objects to a text-output stream.

Public class PrintWriter extends Writer.

Prints formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.

Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform's own notion of line separator rather than the newline character.

Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError().

Since: JDK1.1

Source: Oracle

821 questions
-2
votes
1 answer

Function stops my program

I am trying to use the print function of PrintWriter. When I use this method, my program continues to run but all my other functions doesn't work. public void printVertices(PrintWriter os) { for(int i = 0; i < vert.size(); i++) { …
Jay Lee
  • 23
  • 4
-2
votes
1 answer

out.println() in Spark isn't working for me. Everything is staying on the same line

When I copy the exact same code into the REPL it works, but in the spark shell for scala it writes to the text file, but not on separate lines. val out = new PrintWriter("TestAverages.txt") for(i <- 0 to 10) out.println(i) out.close() It gives me…
-2
votes
2 answers

no suitable constructor found for PrintWriter(File, boolean)

File file = new File("output.txt"); PrintWriter output = new PrintWriter(file,true); When I use PrintWriter(file,true) it's show me error "no suitable constructor found for PrintWriter(File, boolean)" how to solve it ,Thanks
Waleed
  • 47
  • 3
-2
votes
2 answers

Check if file already exist in the same path

I want to check if a specific file already exist in the same folder. If it doesn't exist then create a new file and type in certain thing. for example. if filePath = test.txt and test.txt doesn't exist. Create a new file name test.txt and put 12345…
FeCH
  • 133
  • 3
  • 15
-2
votes
2 answers

Exception - printStackTrace(Printwriter s) method

I would like to make you think about a tiny problem using the method printStackTrace(PrintWriter s). I need to use it in append mode. The following example is explaining what I mean: try { } catch (Exception e) { try { …
-2
votes
1 answer

How to create a file with a different name every time

I am making a program which exports some text to a text file every time you click a button, i want it so that every time you clcik the button the text file has a new name so the text file doesn't get replaced every time. I've tried this code …
Dragon4c3
  • 77
  • 1
  • 10
-2
votes
2 answers

java Constructor of class Printwriter

In one of the sample code I saw, there is such a line: PrintWriter pw = new PrintWriter("$$$temp$$$.$$$"); What is the "$" sign mean in this context? Is it something like a wildcard?
AAAAAAAAAAAA
  • 37
  • 1
  • 2
  • 8
-2
votes
1 answer

Unusual outcome while writing to file

I am having trouble while writing to file using the PrintWriter. Following is my code: String abc = request.getParameter("textAreaField"); //String is "a b c" (with spaces) String fileA = dir + "/A"; PrintWriter fileWriterA = new PrintWriter(new…
Hemang
  • 390
  • 3
  • 20
-2
votes
1 answer

how to stop active thread stored in vector list having bufferreader and printwriter in it

Server.java public synchronized static void logout(String str) throws IOException{ Enumeration e = v1.elements(); while(e.hasMoreElements()){ Serverthread stm = (Serverthread)e.nextElement(); stm.send(str); } …
-2
votes
2 answers

Import statements for PrintWriter

I was searching for information on how to write text from Java to a file and I read this question How do I create a file and write to it in Java? however, none of the answers included what needs to be imported to make PrintWriter work.…
Ungeheuer
  • 1,393
  • 3
  • 17
  • 32
-2
votes
1 answer

Testing test = new Testing(score);Java - Printerwriter

I'm doing a snake game, and I want after the game is over, the score is saved in a file I did this, but there's error in the two lines that sends the value to the Testing Class private boolean isGameOver(int headLocX, int headLocY) { for (int i…
-2
votes
1 answer

How to store data in a file called questions.list

I am currently tring to store data in a file that is going to be called questions.list (a file object)However i am unable to this, i suspect there a few problems/missing parts in my code(as i have a very basic knowledge on objects). Could anyone…
-2
votes
1 answer

Write a program that reads a line of text and then replace a word with another

Before I move on to my question, I just wanna say that I'm completely new to Java and know little about it as I'm taking Java classes in school and I think I love the language but to be honest I got frustrated by the way the class is So I need to…
Beginner
  • 23
  • 1
  • 3
-2
votes
2 answers

Java printwriter only writes one line

My java program only writes one line to txt file. code:Main: package hu.hymosi.tut; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Random; public class Main { public static void main(String[] args) { …
user1624715
  • 1
  • 1
  • 2
-3
votes
1 answer

printWriter does not print to file

I run this code but i found the output file empty. public static void main(String[] args) { try { File outputFile=new File("out"); PrintWriter output= new PrintWriter(outputFile); output.println("test"); } catch…
Mohammed Ait
  • 139
  • 2
  • 8
1 2 3
54
55