printwriter

I created a PrintWriter with autoflush on; why isn't it autoflushing?

My client is a web browser, and sending request to myserver using this url: http://localhost This is the server side code. The problem lies in the run method of the ServingThread class. class ServingThread implements Runnable{ private Socket socket ; public ServingThread(Socket socket){ this.socket = socket ; System....

PrintWriter exception: String index out of range.

I'm trying to read a file then append some text to a certain place in the file (ie. @ offset jabjab). The problem occurs when i'm trying to write to the file at offset jabjab. what's the error? File contents: Mi <?xml Version="1.0"?> _ File f = new File("data.dat"); String brstring = null; String entrystring = null; try ...

Java server-client | server wont receive second request

I'm trying to write a client and time server for an assignment and I'm having trouble getting the server to receive the second request from the client. The first request goes through fine without a hitch. then it just stalls. I'm actually pretty lost in this whole thing and rather uncomfortable with java still, so I have no idea what I'm...

Using PrintWriter and OutputStream

Hello again! I am creating a project with struts and I have a problem using Jasper IReports. I want to export some info into a pdf file and I keep getting the java.lang.IllegalStateException: getOutputStream() has already been call... Exception due to openning a ServletOutputStream in my code when the page already opens a PrintWriter. ...

ByteArrayOutputStream to PrintWriter (Java Servlet)

Writing generated PDF (ByteArrayOutputStream) in a Servlet to PrintWriter. I am desperately looking for a way to write a generated PDF file to the response PrintWriter. Since a Filter up the hierarchy chain has already called response.getWriter() I can't get response.getOutputStream(). I do have a ByteArrayOutputStream where I generat...

Java: Difference between PrintStream and PrintWriter

What is the difference between PrintStream and PrintWriter? They have much methods in common. I always mix up this classes because of that reason. And I think we can use them for exactly the same. But there has to be a difference. Otherwise there was only one class. I first searched on StackOverflow, but not yet this question. ...

Data persistance with BufferedReader and PrintWriter?

I have this simple application with a couple of classes which are all related. There's one, the main one, for which there is only one instance of. I need to save save and load that using a text stream. My instructor requirement is BufferedReader to load the stream and PrintWriter to save it. But is this even possible? To persist a data ...

Problem processing large data using Applet-Servlet communication

Hi everyone. I have an Applet that makes a request to a Servlet. On the servlet it's using the PrintWriter to write the response back to Applet: out.println("Field1|Field2|Field3|Field4|Field5......|Field10"); There are about 15000 records, so the out.println() gets executed about 15000 times. Problem is that when the Applet gets t...

In Java, can I consolidate two similar functions where uses JspWriter and the other PrintWriter?

I have the following class, which as you will see has rather a rather redundant formatNameAndAddress method: package hu.flux.helper; import java.io.PrintWriter; import javax.servlet.jsp.JspWriter; // A holder for formatting data public class NameAndAddress { public String firstName; public String middleName; public String lastNam...

Shouldn't a method that receives java.lang.Object as input also receive javax.servlet.jsp.JspWriter as input?

I wanted to consolidate two functions. After getting a viable solution, I decided to play with the code a bit further, and came up with this: package hu.flux.helper; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.i...

Sentinel Value to Close FileWriter (Java)

I'm trying to make a basic program that allows a user to create a text file and add a list of words to it. When the user writes "stopnow" - the file should close. Unfortunately, right now it's just an infinite loop. What am I doing wrong: import java.util.Scanner; import java.io.*; public class WordList { public static void ...

Specifying file location for PrintWriter class (Java) and automatically appending .txt

so let's say I ask the user to specify what he wants to call a new file System.out.println("What do you want to call the file?"); String outputFile = keyboard.nextLine(); now to write the file I would do: PrintWriter outputFile = new PrintWriter(fileName); My question are: I know by default it saves to the local folder. How do I...