Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:05:00+00:00 2026-06-04T17:05:00+00:00

I converted a doc file to html and displayed that doc file on my

  • 0

I converted a doc file to html and displayed that doc file on my jeditorepane .

This program is working on my admin account. When I login in with a user account in my windows xp that file is not displayed.

try
{

               File docFile=new File("c:\\159.doc");   // file object was created
             FileInputStream finStream=new FileInputStream(docFile.getAbsolutePath()); 
             HWPFDocument doc=new HWPFDocument(finStream);

       WordExtractor wordExtract=new WordExtractor(doc);
         Document newDocument = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument();
    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(newDocument) ;

    wordToHtmlConverter.processDocument(doc);

    StringWriter stringWriter = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance()
            .newTransformer();
    transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
    transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
    transformer.setOutputProperty( OutputKeys.METHOD, "html" );
    transformer.transform(
            new DOMSource( wordToHtmlConverter.getDocument() ),
            new StreamResult( stringWriter ) );

    String html = stringWriter.toString();

          System.out.println(html);


        FileOutputStream fos; 
            DataOutputStream dos;

           File file= new File("C:\\my.html");
      fos = new FileOutputStream(file);
      dos=new DataOutputStream(fos);
     // dos.writeInt();
      dos.writeUTF(html);

     JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
     editorPane.setEditable(false);


            editorPane.setPage(file.toURL());

           JScrollPane scrollPane = new JScrollPane(editorPane);     

               JFrame f = new JFrame("O'Reilly & Associates");
     // Next line requires Java 1.3
                  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 f.getContentPane().add(scrollPane);
                f.setSize(512, 342);
                f.setVisible(true);
    }catch(Exception e)
    {

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:05:01+00:00Added an answer on June 4, 2026 at 5:05 pm

    You should not use DataOutputStream for writing a string, which is already in your HTML format, as this will create a binary file for you. You will understand this when you open C:\\my.html in notepad. It won’t look like your regular HTML file and is most likely to start with an unprintable character, instead of <HTML> tag.

    Instead you can use a simple FileWriter

    File file= new File("C:\\my.html");
    FileWriter fw = new FileWriter(file);
    fw.write(html);
    fw.flush();
    fw.close();
    

    EDIT :

    Also it is recommended to use file.toURI().toURL() instead of file.toURL() as the latter is a deprecated method. According to java docs

    This method does not automatically escape characters that are illegal
    in URLs. It is recommended that new code convert an abstract pathname
    into a URL by first converting it into a URI, via the toURI method,
    and then converting the URI into a URL via the URI.toURL method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of my coworkers wrote a .NET windows service that converts .doc to .docx
I am trying to create an app that converts html to a pdf doc
Suppose user will upload doc or docx file through our asp.net web UI and
i want to convert an avi file to 3gp using java program. For this
When we try to save msword doc file as html file we get wmz
I have this little code to add a watermark image in a doc file,
I have an situation where i need to convert Doc file into PDF file.
I am looking for an online file conversion site which converts DOCX, DOC, PPT,
Is there any opensource/commercial software that converts ppt, doc, pdf, video, audio into swf
I have hundreds of .doc files with text that I need put on web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.