Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Signed Applet - Problem reading large local files



Thanks Alan. Here is exactly what I did:


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>&nbsp;</P></html>



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

This email sent to email@hidden
References: 
 >Re: Signed Applet - Problem reading large local files (From: Alan McMorran <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.