**
写一个main方法可以实现,导出具体位置具体内容 文本txt
**
package com.lilisasa.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class TestFile {
public static void main(String[] args) {
// public static String TestFIle(String adc){
// write your code here
FileWriter fwriter = null;
try {
String content = "我爱祖国"; //需要保存的内容
String savePath = "E://sy/"; //保存的目录
String fileName = "test.txt";//文件名
File dirFile = new File(savePath);
if (!dirFile.exists()) {
//如果目录不存在就创建
dirFile.mkdirs();
}
//开始写入内容
fwriter = new FileWriter(savePath + fileName);
fwriter.write(content);
System.out.println("导出成功-文件名"+fileName+"在路径下"+savePath);
} catch (Exception e){
e.printStackTrace();
} finally {
try {
//关闭流
assert fwriter != null;
fwriter.flush();
fwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
**
调用本接口 实现文本的导出
**
package com.lilisasa.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class TestFile {
// public static void main(String[] args) {
public static String TestFIle(String adc){
// write your code here
FileWriter fwriter = null;
try {
String content = adc; //需要保存的内容
String savePath = "home/sy/"; //保存的目录
String fileName = "test.txt";//文件名
File dirFile = new File(savePath);
if (!dirFile.exists()) {
//如果目录不存在就创建
dirFile.mkdirs();
}
//开始写入内容
fwriter = new FileWriter(savePath + fileName);
fwriter.write(content);
System.out.println("导出成功-文件名"+fileName+"在路径下"+savePath);
} catch (Exception e){
e.printStackTrace();
} finally {
try {
//关闭流
assert fwriter != null;
fwriter.flush();
fwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return "导入执行完了";
}
}