如何用java调用IE打开本地网页文件? rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package test;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;public class Net { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ URL url=new URL("file://localhost:/d:/2.html"); url.openConnection(); BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream())); String line=null; while((line=br.readLine())!=null){ System.out.println(line); } }catch(Exception e){ e.printStackTrace(); } }} package net;import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch;import com.jacob.com.Variant;public class JacobIE { /** * @param args */ // ie:{0002DF01-0000-0000-C000-000000000046} public static void main(String[] args) { // TODO Auto-generated method stub ActiveXComponent ie = new ActiveXComponent("clsid:0002DF01-0000-0000-C000-000000000046"); Object ieo = ie.getObject(); try { Dispatch.put(ieo, "Visible", new Variant(true)); Dispatch.put(ieo, "AddressBar", new Variant(true)); Dispatch.put(ieo, "StatusText", new Variant("My Status Text")); Dispatch.call(ieo, "Navigate", new Variant("d:/2.html")); } catch (Exception e) { e.printStackTrace(); } }}不知道是不是这个意思,用jacob可以运行ie程序打开d:/2.html这个文件,运行上面程序需要下载jacob,在项目导入jacob.jar,拷贝jacob.dll到system32里面就ok了 Runtime.getRuntime().exec( "\""+System.getenv("ProgramFiles")+"\\Internet Explorer\\IEXPLORE.EXE\" 本地文件名" ); // 路径中若有空格必须用双引号括起来,而字符串常量中的双引号必须用反斜杠转义// 本地文件名可以为:D:\mydoc\myhtml.html (注意如果是字符串常量,反斜杠必须写两个——“\\”),也可以为: file:///D:/mydoc/myhtml.html Swing 中 substance 设置水印的方法是什么? jacob调用dll的函数有两个返回值 java面试的算法题——钱按照比例拆分 自动运行类出现错误 菜鸟请教线程问题 怎样用IO流传各种文件 连接池优惠问题.大家来讨论 经济萧条,IT行业你适合吗? 怎么在一个面板中让一个按钮的尺寸为一般的,为什么我添加一个按钮时把整个面板都给占用了 debug 没问题.但是生成的应用文件却打不开! 请帮忙! 请问java怎么让字符串续行? 请问一下这是哈子意思??
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;public class Net {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
URL url=new URL("file://localhost:/d:/2.html");
url.openConnection();
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream()));
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
}
}catch(Exception e){
e.printStackTrace();
}
}}
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;public class JacobIE { /**
* @param args
*/
// ie:{0002DF01-0000-0000-C000-000000000046}
public static void main(String[] args) {
// TODO Auto-generated method stub
ActiveXComponent ie = new ActiveXComponent("clsid:0002DF01-0000-0000-C000-000000000046");
Object ieo = ie.getObject();
try {
Dispatch.put(ieo, "Visible", new Variant(true));
Dispatch.put(ieo, "AddressBar", new Variant(true));
Dispatch.put(ieo, "StatusText", new Variant("My Status Text"));
Dispatch.call(ieo, "Navigate", new Variant("d:/2.html"));
} catch (Exception e) {
e.printStackTrace();
}
}}
不知道是不是这个意思,用jacob可以运行ie程序打开d:/2.html这个文件,运行上面程序需要下载jacob,在项目导入jacob.jar,拷贝jacob.dll到system32里面就ok了