Question:
reading text from a file in java?
?
2010-05-05 00:56:09 UTC
In Java, is it possible to read text from a file type other than a plain text doc? (.txt extension) like can i make it read text from say i microsoft word doc (.docx) or a .wps doc?

i did try it, i just made a word doc, and put the doc name with extension in my program.
so that line of code reads fileIn = new BufferedReader(new FileReader("doc1.docx"));

and then i did the whole input line bit uno fileIn.readLine() and i didnt use a loop, i only wanted it to read the first line to test. but when i ran the program i got this a bunch of garbage ("PK! ) and actually there was more than that, with this in the middle "[Content_Types].xml"

so in other words it didnt work. so, is there a way to make my file read text from a ".docx" file????
Three answers:
ladaghini
2010-05-05 01:49:18 UTC
A plain text file (e.g. .txt) is a really just a string of characters, and in particular, if it uses the ASCII code to represent the characters, then each character will take up one byte of memory. In other words, all the raw binary data used to store the plain text file are only used to represent the characters in the file, and nothing else.



Plain text files have no formatting. All the text is just one color, one strength, one font, etc. However, word documents (in this case the .docx file) are binaries, meaning, a word processor or program capable of reading word documents (.docx), such as MS Word or iWork's Pages, reads and interprets the binary data of the file into something meaningful.



Also, something interesting about the .docx file is that it is actually just an archive of mostly xml files. You can try it yourself: make a .docx file, type in a sentence or two, save it and then make a copy of the file, change the file's extension to .zip (from .docx), and then extract the zip file. Now look into the different xml files of the archive.
?
2016-06-02 11:59:33 UTC
Reading the file is easy--using the proper data structure to do what you want is less straightforward. What do you need more help with? Also, what data structures do you know about? There are several different ways to do this. One is to use a hash table, another is to create an Object which holds the string and count, then you can use an array list, a binary search tree, or, again, a hash table. Which seems most like to be what you are supposed to do? BTW, if this is NOT for a class, then actually, something like AWK or PERL is probably a better programming language to do this in rather than Java. Edit: Ok, you didn't answer my question about data structures. So here is one idea, you can use a hash table which uses the URL string as a key and holds the integer count as its value. Every time you see a new URL, you simply look it up in the Hash Table, if it's there, then increment its value otherwise add the new URL and set its value to 1.
serafina
2016-04-28 06:22:09 UTC
If you want to understand your youngster and she\he has between 2.5 and 7 years of age then a great process is that https://tr.im/FX4ps , Children Learning Reading.

The benefit that Children Learning Reading program  has around an entire term acceptance understanding class is that it is able to train it's practices simply speaking and enjoyable  small steps.

With Children Learning Reading program you and your son or daughter will be able to pay satisfying time together while they learn to read. No forcing your child to remain through boring ‘monitor marathons ', the classes are very small that they're simple to match in to your daily routine. The entire program consists of 50 lessons and the instructions are made in a way that it will not matter if you miss a few days between them. Therefore your child can continue on the path to studying achievement even when “living gets in the way”'.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...