Originally Posted by dikdikdik
Hi evdog, thank your answer but your code don't run.
var ba:ByteArray = stream.readUTFBytes(stream.bytesAvailable);
The error is
1067: Implicit coercion of a value of type uint to an unrelated type flash.utils:ByteArray.
I use "text editor" code in adobe website to test with text file and MS document file. It can't read characters in MS document. I think the reason is format of Ms document is different with text file.
My AIR application can be explain that : firstly I open ms document file, the air app try to read bytes or use extern API to read, then display in text area. Secondly I will parse data in text area to some paragraph and save to plain text file.
I have problem when read MS document, I try to use readUTFBytes, readBytes but not ok. I search and find another solution that use Actionscript to call extern API e.g ActiveX objects, win32OLE, Microsoft Office Web Components... to read ms word and convert it to text.
My idea is
1. Read ms word by any program
2. convert it to plain text and save as temporary file
3. display it to text area
May be MS word file can contain tables, so I want to use VBA to convert tables to text after step1 and before step 2.
Thank any suggest
Okay... apparently, what you are trying to do (make it globally accessible in all platforms?) is a bit... far-fetched at this level.
Anyhow, here's what I use to read all data from a file stream to a ByteArray, and please note that you should open the entire document synchronously and not asynchronously since looping back and forth would be quite a mess for a document.
With that out of the way, here's the code:
mem is a ByteArray. It doesn't matter how big it is, but if you want to conserve memory, pre-define a valid limit. Though a limit may cap the program and somehow prevents it from opening really large documents.
filestrm is the FileStream that we obtained the file from using the 'open' method. (please no 'openAsync' here)
file is the File that we browsed for earlier.
And... there you go.
We can't use writeBytes because FileStream is not a ByteArray, though its behaviors are exactly like one, therefore... readBytes.
So, that's how you obtain the raw data of the word document. Next step is to interprete that binary data, and luckily, Microsoft provided documents.
^= You can grab the binary specifications for Word 97 - 2007 from that link. It's officially Microsoft's and totally free.
There are just about 210 pages of that document to read. It seems tedious, but if you can understand by the end of the day, you may be able to build something on par with Microsoft Word or OpenOffice Writer.