乔山办公网我们一直在努力
您的位置:乔山办公网 > office365 > java读取word文件的问题-获取office文件路径,office文件格式

java读取word文件的问题-获取office文件路径,office文件格式

作者:乔山办公网日期:

返回目录:office365


可以用poi先将word下载到本地,
在用Runtime.getRuntime().exec(); 调用本地文件

package cn.rain.main;

import java.io.File;
import java.io.IOException;

public class TT {

/**
* @param args
*/
public static void main(String[] args) {
try {
Runtime.getRuntime().exec("C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE aa.doc");
} catch (IOException e) {
// TODO 自动e799bee5baa6e78988e69d83363生成 catch 块
e.printStackTrace();
}
}
}
你的WORD安装路径C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE空格后所加的aa.doc为你的文档文件名(有文件名重复的,可以加路径,写法和安装路径的写法一样)
或者用Runtime.getRuntime().exec("cmd /c \"C:\\temp\\the list.doc\"");
也可以运行

请贴出代码,谢谢。
请关闭输入流,释放资源,谢谢。调用close()方法。
其他貌似没有发现什么问题。

public static String run(String filename){
WordExtractor extractor=null;
String text=null;
try{
FileInputStream in = new FileInputStream (filename);
extractor = new WordExtractor();
text=extractor.extractText(in);
}catch(Exception ex){
//log
return null;
}
return text;
}
public static void main(String[] args){
try{
FileOutputStream out=new FileOutputStream("result.txt");
out.write(WordProcess.run(args[0]).getBytes());
out.flush();
out.close();
}catch(Exception ex){
System.out.println(ex.toString());
}
}

看看这个。模范这样写,试试看。这个代码我试过,没问题,如果这样写还是有问题,那就不是代码的问题了636f70797a686964616f331
在ie6中对于7a64e58685e5aeb9366<input type="file" />通过obj.value是可以获取客户端选择文件的全路径的,但是到ie7就只能获取文件名,这对于onchange事件立即显示图片会有问题,可以用js方法解决

具体代码如下:

<html>
<head>
<title>get file input full path</title>
<script language='javascript'>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>
</html>

Runtime.getRuntime().exec("C:/Program Files/Microsoft Office/OFFICE11/WINWORD.EXE s");

这一行的文zd件位置写错误了吧。应该写到引号外面。这样:

Runtime.getRuntime().exec("C:/Program Files/Microsoft Office/OFFICE11/WINWORD.EXE " + s);

相关阅读

关键词不能为空
极力推荐
  • -office2010产品密钥激活失败,kms激活office2010失败

  • Office2010产品密钥过期或产品激活失来败就会有如下图中的提示,每次打开Excel或Word文件都会提示一次,有点麻烦。如果想更改产品密钥,如下图中点击更改产品密钥也不能打开密钥输入

ppt怎么做_excel表格制作_office365_word文档_365办公网