java 数据输出到txt文件
while(i<MainFunction.AirLineList.size()){AirLineInformationAirLine=MainFunction.AirLi...
while(i < MainFunction.AirLineList.size()){
AirLineInformation AirLine = MainFunction.AirLineList.get(i);
BufferedReader input = new BufferedReader(new FileReader(f));
s1 = AirLine.terminal+" ";
s2 = AirLine.lineID+" ";
s3 = AirLine.planeID+" ";
s4 = AirLine.week+" ";
s5 = AirLine.date+" ";
s6 = AirLine.passengerNumber+" ";
s7 = AirLine.ticketLeft+" ";
s8 = AirLine.fileID+" ";
s9 = AirLine.fileID2+"\n";
string = s1+s2+s3+s4+s5+s6+s7+s8+s9;
//将需要输入到文件内的参数放到String变量里面
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(string);
output.newLine();
input.close();
output.close();
i++;
}
以上是部分输出类里面的代码,AirLineList是一个链表,在输出的时候理想状况是达到一共四行(测试数据一共四组),每行一个AirLineInformation的信息,但是实际测试出来是只有1行,也就是最后一组数据。
百度了之后尝试使用newline(),还是不行,猜测是因为每次都是从第一行开始输出,所以覆盖了吧。求助换行或者指定从第几行输出的方法。 展开
AirLineInformation AirLine = MainFunction.AirLineList.get(i);
BufferedReader input = new BufferedReader(new FileReader(f));
s1 = AirLine.terminal+" ";
s2 = AirLine.lineID+" ";
s3 = AirLine.planeID+" ";
s4 = AirLine.week+" ";
s5 = AirLine.date+" ";
s6 = AirLine.passengerNumber+" ";
s7 = AirLine.ticketLeft+" ";
s8 = AirLine.fileID+" ";
s9 = AirLine.fileID2+"\n";
string = s1+s2+s3+s4+s5+s6+s7+s8+s9;
//将需要输入到文件内的参数放到String变量里面
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(string);
output.newLine();
input.close();
output.close();
i++;
}
以上是部分输出类里面的代码,AirLineList是一个链表,在输出的时候理想状况是达到一共四行(测试数据一共四组),每行一个AirLineInformation的信息,但是实际测试出来是只有1行,也就是最后一组数据。
百度了之后尝试使用newline(),还是不行,猜测是因为每次都是从第一行开始输出,所以覆盖了吧。求助换行或者指定从第几行输出的方法。 展开
7个回答
展开全部
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class TestBaiduKnow {
public static void main(String[] args) throws IOException {
FileOutputStream fs = new FileOutputStream(new File("D:\\text.txt"));
PrintStream p = new PrintStream(fs);
p.println(100);
p.close();
}
}
//简单的一个例子,来模拟输出
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class TestBaiduKnow {
public static void main(String[] args) throws IOException {
FileOutputStream fs = new FileOutputStream(new File("D:\\text.txt"));
PrintStream p = new PrintStream(fs);
p.println(100);
p.close();
}
}
//简单的一个例子,来模拟输出
展开全部
public static void writeFile(String str)
{
File file = new File("src/com/song/demo/test/products.txt");
try {
BufferedWriter bw=new BufferedWriter(new FileWriter(file,true));
bw.write(str+"\r\n\r\n");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
{
File file = new File("src/com/song/demo/test/products.txt");
try {
BufferedWriter bw=new BufferedWriter(new FileWriter(file,true));
bw.write(str+"\r\n\r\n");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
File dest = new File("D:/mudi.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(dest));
writer.write("写入文字到txt中\n");
writer.flush();
writer.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(dest));
writer.write("写入文字到txt中\n");
writer.flush();
writer.close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BufferedWriter output = new BufferedWriter(new FileWriter(f), true);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
outputstream
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询