如题,请问Java如何将mht文件分离为html文件和图片文件夹,如何将html文件和图片文件夹转换为mht文件。
求思路或实现代码。

解决方案 »

  1.   


    import com.chilkatsoft.CkMht;
    import com.chilkatsoft.CkString;public class HtmlToMht {

      static {
        try {
            System.loadLibrary("chilkat");
        } catch (UnsatisfiedLinkError e) {
          System.err.println("Native code library failed to load.\n" + e);
          System.exit(1);
        }
      }  public static void main(String argv[]) 
      {
        // Create a MHT object...
        CkMht mht = new CkMht();
        mht.UnlockComponent("anything for 30-day trial");
        
        String html = "<html><body><img src=\"http://www.chilkatsoft.com/images/dude.gif\"><br>Chilkat Software Inc</body></html>";
        CkString strMht = new CkString();
        boolean success = mht.HtmlToMHT(html,strMht);
        if (!success)
        {
         mht.SaveLastError("lastError.txt");
        }
        else
        {
         // Save the string to a file...
         strMht.saveToFile("output/dude.mht","windows-1252");
        
         // To access the MHT string, do this:
         String mhtString = strMht.getString();
        }
        
      }
    }