Link to home
Create AccountLog in
Avatar of barronrad
barronrad

asked on

Serialization of Non-Serializable objects.. ...

Hello Experts,

Im trying to serialize an extremely complex object. The object refers to non serializable classes such as java.io.PrintWriter and java.io.Reader..

How can i serialize these ? Is there a way ?

I have attached a snippet of one of the classes linked to the object i want to serialize...





import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.Serializable;
 
public class sendLog implements Serializable {
 
	private testLog x;
	private PrintWriter output;
	public sendLog (testLog x, String outputFileName){
		this.x = x;
		try {
			this.output = new PrintWriter(outputFileName);
		}
		catch (FileNotFoundException e){
			System.out.println("Problem with filename: " + outputFileName);
			throw new RuntimeException("sendLog problem");
		}
	}
 
	public EventAcceptor(String outputFileName){
		this.x = null;
		try {
			this.output = new PrintWriter(outputFileName);
		}
		catch (FileNotFoundException e){
			System.out.println("Problem with filename: " + outputFileName);
			throw new RuntimeException("sendLog problem");
		}		
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of aman123_123
aman123_123

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer