Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2007, 06:59 AM
jon jon is offline
Junior Member
 
Join Date: Sep 2007
Posts: 25
Default StringStream() - what am I doing wrong?

I cant seem to use StringStream correctly. Here is what I am trying to use;

Code:
//Initialize
trace("Initializing:.....................................");
getAdditionalFile();

var stringIn = new StringStream($STREAM_IN);
var stringOut = new StringStream($STREAM_OUT);

//var basePath = getAppDir();
var basePath = "F:\\data\\synergy management consulting\\risk maturity\\01 Source\\Scripts\\questionDev\\stringDecoder\\Application";
trace("basePath = "+basePath); 

trace("File.exists(basePath+\"\\in.txt\") = " + File.exists(basePath+"\\in.txt"));

stringIn.readFromFile(basePath+"\\in.txt");

trace("stringIn.getPos = " + stringIn.getPos);
trace("stringIn.eof = " + stringIn.eof);

var lineRead = stringIn.readLine();
var i = 0;

trace("stringIn.readUnicodeString() = " + stringIn.readUnicodeString());
trace("stringIn.readString() = " + stringIn.readString());
trace("stringIn.get() = " + stringIn.get());
trace("stringIn.readLine() = " + stringIn.readLine());
trace("stringIn.uncompress() = " + stringIn.uncompress());

stringOut.writeLine("questions = new Array();");

while(stringIn.eof != true){
	trace("lineRead = " + lineRead);
	trace("stringIn.getPos = " + stringIn.getPos);
	stringOut.writeLine(lineRead);
	readLine = stringIn.readLine();
	i++;
}

stringOut.saveToFile(basePath+"\\out.txt");

stringOut.close();

stringIn.close();
return true;
Sorry about that huge chunk of code. What happens is that it traces;

File.exists(basePath+"\in.txt") = true
stringIn.getPos = -1
stringIn.eof = false
stringIn.readUnicodeString() =
stringIn.readString() =
stringIn.get() = -1
stringIn.readLine() =
stringIn.uncompress() =

and it saves an empty file.

So the file exists. And it saves something. But i'm not successfully doing anything with the FileStream. I was hoping somebody could tell me what i'm doing wrong.

Again, i appologize for the length of this post.
Jon
Reply With Quote
  #2 (permalink)  
Old 10-29-2007, 07:33 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: StringStream() - what am I doing wrong?

Please try to change the first two lines to
Code:
var stringIn = new StringStream;
var stringOut = new StringStream;
, and check whether it will work. Thank you.
Reply With Quote
  #3 (permalink)  
Old 10-29-2007, 07:42 AM
jon jon is offline
Junior Member
 
Join Date: Sep 2007
Posts: 25
Default Re: StringStream() - what am I doing wrong?

None of my traces change but my "out.txt" file does now contain "questions = new Array();".

So a definate improvement.

How should I deal with reading the data in?

Thanks
Jon
Reply With Quote
  #4 (permalink)  
Old 10-29-2007, 08:00 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: StringStream() - what am I doing wrong?

The "readFromFile" method is a static method, so you will have to call it as follows
Code:
stringIn= StringStream.readFromFile(basePath+"\\in.txt");
while
Code:
stringIn.readFromFile(basePath+"\\in.txt");
does not return the content of the text file into "stringIn", but return it into a temporary variable that is discarded.
Reply With Quote
  #5 (permalink)  
Old 10-31-2007, 06:09 AM
jon jon is offline
Junior Member
 
Join Date: Sep 2007
Posts: 25
Default Re: StringStream() - what am I doing wrong?

Thankyou very much, I think I'm nearly there.

However I'm just reading the first line over and over, how do I 'move the read head?'. Maybe a better question is 'How should I best read a .txt file, line by line?'.

Thanks again
Jon
Reply With Quote
  #6 (permalink)  
Old 11-01-2007, 07:54 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: StringStream() - what am I doing wrong?

Code:
var fs = new FileStream(basePath + "\\in.txt", "r");

while (fs.pos < fs.length) {
  var t = fs.readLine();
  trace(t);
}
Reply With Quote
  #7 (permalink)  
Old 11-15-2007, 10:49 PM
jon jon is offline
Junior Member
 
Join Date: Sep 2007
Posts: 25
Default Re: StringStream() - what am I doing wrong?

Thanks very much, that worked a charm.
I'm sure there was a reason I didnt ask that question first
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:37 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.