java获取word路径 java 获取当前路径 - 电脑知识 - 【三明电脑网】_三明电脑维修_三明笔记本电脑维修_监控安装_市区上门维修

全国统一24小时服务热线:400-0000-000400-0000-000  / 1399000000

当前位置:首页 > 电脑知识 > 正文

java获取word路径 java 获取当前路径

发布日期:2020-09-08

摘要:java读取word文件的问题 请贴出代码,谢谢。 请关闭输入流,释放资源,谢谢。调用close()方法。 其他貌似没有发现什么问题。 public static String run(String ...

java获取word路径

java读取word文件的问题

请贴出代码,谢谢。

请关闭输入流,释放资源,谢谢。

调用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){//logreturn 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());}}看看这个。

模范这样写,试试看。

这个代码我试过,没问题,如果这样写还是有问题,那就不是代码的问题了。

如何查看java读取文件的路径

例如在上面的例子中:\xhuoj\konw\:G;\src\\xhuoj\.(点号)代表当前目录。

getCanonicalPath()就会把它解析为当前目录但是getAbsolutePath()会把它解析成为目录名字(目录名字是点号)File类有两个常用方法可以得到文件路径一个是:getCanonicalPath(),另一个是:getAbsolutePath(),可以通过File类的实例调用这两个方法例如file.getAbsolutePath()其中file是File的实例对象。

下面是一个具体例子:123456789101112131415public class PathTest{public static void main(String[] args){File file = new File("baiduG:\.\try{System.out.println(file.printStackTrace().getCanonicalPath())。

下面是上面程序在我电脑上的输出;baidu");System;}}}getAbsolutePath()和getCanonicalPath()的不同之处在于,getCanonicalPath()得到的是一个规范的路径,而getAbsolutePath()是用构造File对象的路径+当前工作目录.out;} catch (IOException e){e.println(file.getAbsolutePath());.\src\...

java中获取文件路径的几种方式

获取当前类的所在工程路径;如果不加“/”File f = new File(this.getClass().getResource("").getPath());System.out.println(f);结果:C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test获取当前类的绝对路径;第二种:File directory = new File("");//参数为空String courseFile = directory.getCanonicalPath() ;System.out.println(courseFile);结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前类的所在工程路径;第三种:URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");System.out.println(xmlpath);结果:file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt获取当前工程src目录下selected.txt文件的路径第四种:System.out.println(System.getProperty("user.dir"));结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前工程路径第五种:System.out.println( System.getProperty("java.class.path"));结果:C:\Documents and Settings\Administrator\workspace\projectName\bin获取当前工程路径...

在java中怎么获得,本文件的路径

File类有两个常用方法可以得到文件路径一个是:getCanonicalPath(),另一个是:getAbsolutePath(),可以通过File类的实例调用这两个方法例如file.getAbsolutePath()其中file是File的实例对象。

下面是一个具体例子: public class PathTest{ public static void main(String[] args) { File file = new File(".\\src\\baidu"); System.out.println(file.getAbsolutePath()); try { System.out.println(file.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } }} getAbsolutePath()和getCanonicalPath()的不同之处在于,getCanonicalPath()得到的是一个规范的路径,而getAbsolutePath()是用构造File对象的路径+当前工作目录。

例如在上面的例子中.(点号)代表当前目录。

getCanonicalPath()就会把它解析为当前目录但是getAbsolutePath()会把它解析成为目录名字(目录名字是点号)。

下面是上面程序在我电脑上的输出: G:\xhuoj\konw\.\src\baiduG:\xhuoj\konw\src\baidu...

java 怎么获取指定路径文件

Java读取相对路径文件是的前提也是相对的:文件必须位于classpath下面,否则随便一个相对文件是没法读取的。

用IDE创建一个工程,一般都会有一个sc的目录,这个sc就是工程的classpath目录了,只要在sc目录或其子目录下的文件,在程序代码中都可以使用相对路径的方式来读取,这里的相对路径和文件系统的相对路径概念上也许有点差异。

JAVA读取WORD,EXCEL,PDF文件的方法是什么呢?

JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法 OFFICE文档使用POI控件,PDF可以使用PDFBOX0.7.3控件,完全支持中文,用XPDF也行,不过感觉PDFBOX比较好,而且作者也在更新。

水平有限,万望各位指正 WORD: impot og.apache.lucene.document.Document; impot og.apache.lucene.document.Field; impot og.apache.poi.hwpf.extacto.WodExtacto; impot java.io.File; impot java.io.InputSteam; impot java.io.FileInputSteam; impot com.seach.code.Index; pulic Document getDocument(Index index, Sting ul, Sting title, InputSteam is) thows DocCenteException { Sting odyText = null; ty { WodExtacto ex = new WodExtacto(is);is是WORD文件的InputSteam odyText = ex.getText(); if(!odyText.equals("")){ index.AddIndex(ul, title, odyText); } }catch (DocCenteException e) { thow new DocCenteException("无法从该Mociosoft Wod文档中提取内容", e); }catch(Exception e){ e.pintStackTace(); } } etun null; } Excel: impot og.apache.lucene.document.Document; impot og.apache.lucene.document.Field; impot og.apache.poi.hwpf.extacto.WodExtacto; impot og.apache.poi.hssf.usemodel.HSSFWokook; impot og.apache.poi.hssf.usemodel.HSSFSheet; impot og.apache.poi.hssf.usemodel.HSSFRow; impot og.apache.poi.hssf.usemodel.HSSFCell; impot java.io.File; impot java.io.InputSteam; impot java.io.FileInputSteam; impot com.seach.code.Index; pulic Document getDocument(Index index, Sting ul, Sting title, InputSteam is) thows DocCenteException { StingBuffe content = new StingBuffe(); ty{

上一篇:万能视频修复软件 v3.2.0.1302 万能视频修复软件

下一篇:invalid id password boot device not found