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



I also tried using a StringBuffer and it works fine. Thanks Michael & Neil.

String ret = "";
try{
String thisLine = null;
StringBuffer buffer = new StringBuffer( );

BufferedReader myInput = new BufferedReader(new FileReader(fn));
while ((thisLine = myInput.readLine()) != null) {
buffer.append( thisLine );
buffer.append( "\n" );
}
myInput.close();
ret = buffer.toString( );
}
catch (Exception e) {
ret = "Cannot load, exception!";
}

Sincerely,
Ali.






<html><P>&nbsp;</P></html>



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