java 如何把运行结果保存到.txt文件中
我想把结果存到一个.txt文件中,下面是运行的主程序importjava.util.*;classtest{publicstaticfinalvoidmain(Strin...
我想把结果存到一个.txt文件中,下面是运行的主程序
import java.util.*;
class test {
public static final void main(String[] args)
{
LocalizationService ls = new LocalizationServiceMockup();
try {
List locs = ls.localize();
Iterator i = locs.iterator();
while (i.hasNext()) {
MoteLocation ml = (MoteLocation) i.next();
System.out.print("id: "); System.out.print(ml.id);
System.out.print(" x: "); System.out.print(ml.x);
System.out.print(" y: "); System.out.print(ml.y);
System.out.print(" confidence: "); System.out.println(ml.confidence);
}
} catch (LocalizationBusyException e) {
System.out.println("Error: Localization busy.");
}
}
}; 展开
import java.util.*;
class test {
public static final void main(String[] args)
{
LocalizationService ls = new LocalizationServiceMockup();
try {
List locs = ls.localize();
Iterator i = locs.iterator();
while (i.hasNext()) {
MoteLocation ml = (MoteLocation) i.next();
System.out.print("id: "); System.out.print(ml.id);
System.out.print(" x: "); System.out.print(ml.x);
System.out.print(" y: "); System.out.print(ml.y);
System.out.print(" confidence: "); System.out.println(ml.confidence);
}
} catch (LocalizationBusyException e) {
System.out.println("Error: Localization busy.");
}
}
}; 展开
3个回答
展开全部
import java.io.*;
import java.util.*;
class test {
public static final void main(String[] args) {
LocalizationService ls = new LocalizationServiceMockup();
try {
BufferedWriter bw=new BufferedWriter(new FileWriter("myprog.log"));
List locs = ls.localize();
Iterator i = locs.iterator();
while (i.hasNext()) {
MoteLocation ml = (MoteLocation) i.next();
String strLine="id: "+String.valueOf(ml.id);
strLine+=" x: "+String.valueOf(ml.x);
strLine+=" y: "+String.valueOf(ml.y);
strLine+=" confidence: "+String.valueOf(ml.confidence)+"\n";
bw.write(strLine);
}
bw.flush();
bw.close();
} catch (LocalizationBusyException e) {
System.out.println("Error: Localization busy.");
} catch (IOException ioe) {
System.out.println("IO Exception");
}
}
}
//采用BufferedWriter和FileWriter来完成对txt文件的写入
import java.util.*;
class test {
public static final void main(String[] args) {
LocalizationService ls = new LocalizationServiceMockup();
try {
BufferedWriter bw=new BufferedWriter(new FileWriter("myprog.log"));
List locs = ls.localize();
Iterator i = locs.iterator();
while (i.hasNext()) {
MoteLocation ml = (MoteLocation) i.next();
String strLine="id: "+String.valueOf(ml.id);
strLine+=" x: "+String.valueOf(ml.x);
strLine+=" y: "+String.valueOf(ml.y);
strLine+=" confidence: "+String.valueOf(ml.confidence)+"\n";
bw.write(strLine);
}
bw.flush();
bw.close();
} catch (LocalizationBusyException e) {
System.out.println("Error: Localization busy.");
} catch (IOException ioe) {
System.out.println("IO Exception");
}
}
}
//采用BufferedWriter和FileWriter来完成对txt文件的写入
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
try{
FileWriter fw = new FileWriter("PathSaved.txt");
PrintWriter out = new PrintWriter(fw,false);
out.print(运行结果);
fw.close();
out.close();
} catch(IOException er){
er.printStackTrace();
}
FileWriter fw = new FileWriter("PathSaved.txt");
PrintWriter out = new PrintWriter(fw,false);
out.print(运行结果);
fw.close();
out.close();
} catch(IOException er){
er.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用文件输入输出流来写啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |