第一种:Object获取项目中的propertiesInputStream in = Object. class .getResourceAsStream( "/com/demo/conf.properties" );第二种:直接获得本地配
第一种:Object获取项目中的properties
InputStream in = Object. class .getResourceAsStream( "/com/demo/conf.properties" );
第二种:直接获得本地配置文件properties
FileInputStream in = new FileInputStream("D:workdemoconf.properties");
//加载properties文件
Properties prop = new Properties();
prop.load(in);
//从配置文件中获取 页面的位置,此处url为网页的绝对路径并解决乱码,如:d:/demo/index.html
String url = new String(prop.getProperty( "csv_url" ).trim().getBytes("ISO-8859-1"),"gbk");
//根据url打开网页
private static void browse(String url) throws ClassNotFoundException, IllegalAccessException,
IllegalArgumentException, InterruptedException, InvocationTargetException, IOException,NoSuchMethodException {
String osName = System.getProperty("os.name", "");
if (osName.startsWith("windows")) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} else if (osName.startsWith("Mac OS")) {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
} else {
// Unix or linux
String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
"mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++)
if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if (browser == null)
throw new NoSuchMethodException("Could not find WEB browser");
else
Runtime.getRuntime().exec(new String[] { browser, url });
}}
相关文章教程推荐:java入门教程
--结束END--
本文标题: java如何打开本地html文件
本文链接: https://www.lsjlt.com/news/2873.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0