Java如何把list数据导入txt文件?
3个回答
展开全部
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) throws IOException {
List<Integer> list=new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
list.add(i);//集合中放入0-9
}
//下面是写文件
boolean flag = false;
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter("d:/test.txt", true);
bw = new BufferedWriter(fw, 100);
for (Integer integer : list) {
bw.write(integer+"");
}
flag = true;
} catch (IOException e) {
System.out.println("写入文件出错");
flag = false;
} finally {
if (bw != null) {
bw.flush();
bw.close();
}
if (fw != null)
fw.close();
}
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) throws IOException {
List<Integer> list=new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
list.add(i);//集合中放入0-9
}
//下面是写文件
boolean flag = false;
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter("d:/test.txt", true);
bw = new BufferedWriter(fw, 100);
for (Integer integer : list) {
bw.write(integer+"");
}
flag = true;
} catch (IOException e) {
System.out.println("写入文件出错");
flag = false;
} finally {
if (bw != null) {
bw.flush();
bw.close();
}
if (fw != null)
fw.close();
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
file输入输出流
fileinputstream
fileinputstream
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询