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> </P></html>
>From: Michael Rasmussen <email@hidden>
>Reply-To: Michael Rasmussen <email@hidden>
>To: Alan McMorran <email@hidden>
>CC: "email@hidden"
<email@hidden>
>Subject: Re: Signed Applet - Problem reading large local files
>Date: Wed, 8 Dec 2004 10:02:20 -0600
>
>Using a string buffer may help you out. Also, I am not sure at all on
>this so I am asking what the maximum size for a string is, A 512 KB
>string seems big.
>Michael
>
>
>On Wed, 08 Dec 2004 15:38:33 +0000, Alan McMorran
<email@hidden> wrote:
> > 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
>
>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