We help IT Professionals succeed at work.

Read in file using java to seperate text and images

harlanhugh
harlanhugh asked
on
731 Views
Last Modified: 2008-09-20
I want to read in a file using Java.
1. This file could have text, images or both. I would like to be able to seperate the two.
2. I need to be able to grab the text to insert in our database and leave references to where the images are on the hard drive

I'm not concerned about part 2 of this question, it is only to give context to the first part. Any help, ideas or references on the web would be greatly appreciated.

Harlan.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
How would it have both - what kind of file is it?

Author

Commented:
One way would be to open up WordPad, type some text and then cut and paste an image in it. Save the file as *.rtf. What I am trying to do is then seperate those two in my java program. Seperate the bytes, imputStreams... however.

Thanks,

Harlan
CERTIFIED EXPERT
Top Expert 2016

Commented:
Well how you read it in Java depends completely what kind of file you've got, so unless we know that, we can't help
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
It would be an rtf file with text and images in it.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
if you keep your rtf files simple then you can use RTFEditorKit

Author

Commented:
Ok, I actually have tried the RTFEditorKit and it works just fine for ASCII. But if I have Chinese characters in there it does not work properly. I was hoping to find another way to do that here. So is there a way to tell it to read the file text in as "UTF-8" or "UTF-16"? I was unable to find a way to do that. It just turned all the Chinese characters into gibberish.
perhaps you are not setting charset, can you post the code?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Try using an InputStreamReader as the argument to read with encoding set to UTF-8 or 16
CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.