• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

MS-Word and Java

 
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: 43016
76
  • 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: 43016
76
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
    Bookmark Topic Watch Topic
  • New Topic