StringWriter stringOutput = new StringWriter();
FileReader fr = new FileReader(fn);
PrintWriter pw = new PrintWriter(stringOutput, true);
char c[] = new char[4096];
int read = 0;
// Read (and print) till end of file
while ((read = fr.read(c)) != -1)
pw.write(c, 0, read);
fr.close();
pw.close();
ret = stringOutput.toString();
Sincerely,
Ali.
<html><P> </P></html>
>From: Alan McMorran <email@hidden>
>To: "email@hidden"
<email@hidden>
>Subject: Re: Signed Applet - Problem reading large local files
>Date: Wed, 08 Dec 2004 15:38:33 +0000
>
>Since I seem to have gotten into the bad habit of replying to my own
>emails...
>
> > Then put the string into a file, but the time taken increased
exponentially
> > as the number of objects increased. When I changed it to:
> >
> > PrintWriter fileOutput = new PrintWriter(new FileWriter(new
> > File("outputFile"));
> >
> > For (int I=0; I<objects.length; I++){
> > fileOutput.println(objects[I].outputXML());
> > }
> >
> > I know it's not an exact solution, and puts the output into a file
rather
> > than to a variable, but that's because I'm using a FileWriter for
my
> > implementation, and I'm sure there are other ways to use a
PrintWriter
> > rather than outputting to a file that would solve your problem.
>
>You can do:
>
>StringWriter stringOutput = new StringWriter();
>PrintWriter printOutput = new PrintWriter(stringOutput);
>For (int I=0; I<objects.length; I++){
> printOutput.println(objects[I].outputXML());
>}
>printOutput.close();
>
>Return stringOutput.toString();
>
>And that should return a String and doesn't seem to have the bottlenecks
you
>get when doing += on a String object.
>
>Hope that helps.
>
>Alan
>
>
> _______________________________________________
>Do not post admin requests to the list. They will be ignored.
>Java-dev mailing list (email@hidden)
>Help/Unsubscribe/Update your Subscription:
>http://lists.apple.com/mailman/options/java-dev/email@hidden
>
>This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden