展开全部
public static void main(String[] args) {
try {
copyFile("D:\\数字化烧结/qm截图.jpg", "d:/testcopyfile.out");
System.out.println(readFileText("D:/jslib/test.html"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void copyFile(String src, String tar) throws IOException {
FileOutputStream fo = new FileOutputStream(tar);
FileInputStream fi = new FileInputStream(src);
byte[] srcBytes = new byte[fi.available()];
fi.read(srcBytes);
fi.close();
fo.write(srcBytes);
fo.close();
}
public static String readFileText(String src) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(src));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
br.close();
return sb.toString();
}
copyFile可以根据源路径和目标路径复制文件e68a84e8a2ad3231313335323631343130323136353331333332613761,无论什么样子的文件,有什么内容都适用。
readFileText可以读取目标文本文件,注意是文本文件,因为使用了字符流。你提问里都说带中文,我想应该就是读文本文件吧。(不一定是.txt,只要文件内容是字符)