我现在想创建一个制定编码的文件,用encoding设定编码的格式,我不知道如何设置。
public void createFile(String relativePath, String fileName,
String content, String encoding) throws AdaptorException {
File parent = new File(root, relativePath);
if (!parent.exists()) {
throw new AdaptorException("relativePath not existed");
}
File file = new File(parent, fileName);
if (!file.exists()) {
FileWriter resultFile = null;
try {
resultFile = new FileWriter(file);
PrintWriter printFile = new PrintWriter(resultFile);
String strContent = content;
printFile.println(strContent);
System.out.println("Successful");
} catch (IOException e) {
throw new AdaptorException(e.getMessage());
}finally {
if(resultFile !=null){
try{
resultFile.close();
}catch (IOException e) {
}
}
}
}
}
创建完成后,我想读取该文件,也是用encoding设定读取时的文件编码格式
public String readTextFile(String relativePath, String fileName,
String content, String encoding) throws AdaptorException
希望高手给我一些讲解,谢谢 我是新手