package com.ytxl.test;import java.io.*;import com.jacob.*;public class ReadWord { public static String path1 = "d:/abc.doc"; public static String path2 = "d:/abcd.txt"; public static FileOutputStream fos = null; public static FileInputStream fis = null; public static void main(String[] args) {
ReadWord rw = new ReadWord(); // ReadWord.readword(path1, path2); ReadWord.parse(path1, path2); System.out.print("OK"); } public static void parse(String path1, String path2) { try {
fis = new FileInputStream(path1);
fos = new FileOutputStream(path2);
} catch (FileNotFoundException e) { System.out.print("文件不存在!");
}
boolean flag = false; while (!flag) { char c = 0;
try {
c = (char) fis.read();
} catch (IOException e) { e.printStackTrace();
}// String temp1 = "a";
//
// String tempc = "" + c;
// if (temp1 != tempc) {
// tempc = "c";
// }
//
// c = tempc.charAt(0);
//
// try {
// fos.write((char) c);
// } catch (IOException e) {
//
// e.printStackTrace();
// }
// if (c == -1)
// flag = true;
//
// }
try {
fis.close();
} catch (IOException e) { e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) { e.printStackTrace();
}
} public static void readword(String path1, String path2)
// 实现对文件的复制
{ try {
fis = new FileInputStream(path1);
fos = new FileOutputStream(path2);
} catch (FileNotFoundException e) { System.out.print("文件不存在!");
}
boolean flag = false; while (!flag) { char c = 0;
try {
c = (char) fis.read();
} catch (IOException e) { e.printStackTrace();
}
try {
fos.write((char) c);
} catch (IOException e) { e.printStackTrace();
}
if (c == -1)
flag = true; }
try {
fis.close();
} catch (IOException e) { e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) { e.printStackTrace();
}
}}
我本来计划写一个处理word的程序的,
把word文件读出来,格式化后变成excel的格式的文档的。
所以我一步一步在做,不知道怎么搞的,加了中间的注释就死跑不出来了。
复制功能是好的。
高手指点啊!