• Post Reply Bookmark Topic Watch Topic
  • New Topic

MS-Word and Java  RSS feed

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to put an image file into MS-word file using java ?
I've done like this ...

String st = "d:/SALKAR/temp";
File fil = new File(st);
fil.mkdir();
String str = "d:/SALKAR/sunset.jpg";
BufferedInputStream bis = new BufferedInputStream(new DataInputStream(
new FileInputStream(str)));
BufferedOutputStream bos = new BufferedOutputStream(new DataOutputStream(
new FileOutputStream(st + "/" + "WordPic.dat")));
byte[] data = new byte[1024];
while (bis.read(data) != -1) {
bos.write(data);
}
bos.flush();
bos.close();

But it wont work properly ! I'm unable to open as MS-Word Format
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOC is not a plain text format; it is a highly structured binary format. You can't use simple java.io classes to work with them - you need to use a library that understands it, like Apache POI.
[ October 07, 2008: Message edited by: Ulf Dittmer ]
 
Amardeep Salkar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
DOC is not a plain text format; it is a highly structured binary format. You can't use simple java.io classes to work with them - you need to use a library that understands it, like Apache POI.

[ October 07, 2008: Message edited by: Ulf Dittmer ]


Thanks, but could you please help me in writing a program for that, Do i have to load some jar files regarding that ?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you need to download the POI library. The HWPF Quick Guide gives a few coding hints, and points to the unit tests that contain more code examples.

The DOC part of POI isn't nearly as well documented as the XLS part, so be prepared to spend time reading the javadocs, and piece the code together method call by method call.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you post a question on JavaRanch, please carefully choose one forum.

You posted this in the SCJP forum, but your question doesn't have anything to do with the SCJP exam. I will move this to a more appropriate forum for you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!