java写一段程序 实现对本地路径下一word文档打开并且另存为指定的格式的文件,请问能实现吗? 求实例代码
发布网友
发布时间:2022-05-08 03:23
我来回答
共1个回答
热心网友
时间:2023-11-24 17:55
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class SaveFile {
public static void main(String[] args) {
String olddir = "d:" + File.separator + "test.docx";
String newdir = "e:" + File.separator + "newtest.tt";
saveFileToAnotherDir(olddir, newdir);
}
public static void saveFileToAnotherDir(String olddir, String newdir) {
File fo = new File(olddir);
File fn = new File(newdir);
FileReader fr;
FileWriter fw;
try {
fr = new FileReader(fo);
fw = new FileWriter(fn);
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
String line = null;
while((line = br.readLine()) != null) {
bw.write(line);
bw.flush();
}
bw.close();
br.close();
fw.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
}
类似这样的可以实现
热心网友
时间:2023-11-24 17:55
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class SaveFile {
public static void main(String[] args) {
String olddir = "d:" + File.separator + "test.docx";
String newdir = "e:" + File.separator + "newtest.tt";
saveFileToAnotherDir(olddir, newdir);
}
public static void saveFileToAnotherDir(String olddir, String newdir) {
File fo = new File(olddir);
File fn = new File(newdir);
FileReader fr;
FileWriter fw;
try {
fr = new FileReader(fo);
fw = new FileWriter(fn);
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
String line = null;
while((line = br.readLine()) != null) {
bw.write(line);
bw.flush();
}
bw.close();
br.close();
fw.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
}
类似这样的可以实现
热心网友
时间:2023-11-24 17:55
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class SaveFile {
public static void main(String[] args) {
String olddir = "d:" + File.separator + "test.docx";
String newdir = "e:" + File.separator + "newtest.tt";
saveFileToAnotherDir(olddir, newdir);
}
public static void saveFileToAnotherDir(String olddir, String newdir) {
File fo = new File(olddir);
File fn = new File(newdir);
FileReader fr;
FileWriter fw;
try {
fr = new FileReader(fo);
fw = new FileWriter(fn);
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
String line = null;
while((line = br.readLine()) != null) {
bw.write(line);
bw.flush();
}
bw.close();
br.close();
fw.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
}
类似这样的可以实现