怎样让写入文本(txt格式)的内容换行?急问,在线等! write("\r\n");就可以换行了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看这个//: FileWriterTest.java/** 一个关于FileWriter的例子 * @author Soloist * @author http://www.soloist.com * @version 1.0 */import java.io.*;public class FileWriterTest{ public static void main(String[] args){ int people; int[] chinese,english,math; File filePath; BufferedWriter bufout; InputStreamReader stdin=new InputStreamReader(System.in); //键盘输入 BufferedReader bufin=new BufferedReader(stdin); try{ System.out.println("======简易成绩单======"); System.out.print("请输入人数:"); people=Integer.parseInt(bufin.readLine()); System.out.println("请输入成绩存盘路径:"); filePath=new File(bufin.readLine()); bufout=new BufferedWriter(new FileWriter(filePath)); chinese=new int[people]; english=new int[people]; math=new int[people]; for(int i=0;i<people;i++){ System.out.println((i+1)+"号"); System.out.print("语文:"); chinese[i]=Integer.parseInt(bufin.readLine()); System.out.print("英文:"); english[i]=Integer.parseInt(bufin.readLine()); System.out.print("数学:"); math[i]=Integer.parseInt(bufin.readLine()); } System.out.println("已完成登记所有成绩!"); System.out.println("=========打印成绩单到"+filePath.getPath()+"========="); for(int i=0 ;i<people;i++){ bufout.write((i+1)+"号 语文:" + chinese[i]); bufout.write(" 英文:"+english[i]); bufout.write(" 数学:"+math[i]); bufout.newLine(); bufout.flush(); //写入文件,经过我的测试,不加flush()函数一样可以写入数据 } stdin.close(); bufin.close(); bufout.close(); } catch(IOException E){ System.out.println("发生I/O错误!"); } } } infor是area对象 infor.setLineWrap(true);//让Area自动换行 写到记事本的文件里面,怎么用infor.setLineWrap(true)? 其实很简单:out是 FileWriterout.write("内容");out.newLine();//换行搞定! PrintWriter outprint = new PrintWriter(new FileWriter("c:/文件.txt"));outprint.println("输出一行"); 看看这段代码/******************** WriteFile.java ********************/import java.io.*;public class WriteFile { public static void main(String args[]) throws Exception { BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter( new FileWriter("line.txt")); String s; while (true) { System.out.print("块﹃: "); System.out.flush(); s=br.readLine(); if (s.length()==0) break; bw.write(s); bw.newLine();//这句就是换行的 } bw.close(); } } Windows中的回车版本是"\r\n"Unix/Linux中的回车是"\n"OS/2中的回车版本是"\r"如果乱来,在Windows中的记事本里只能是"黑方格",但用ultraedit打开这个txt,就没有了 write(System.getProperty("line.separator")); 请求帮助,查询出错,不知道错在哪? 左移运算符求解1<<32 fileoutputstream的关闭问题 解析日期时错误 数据的追加 在线等 jbutton按钮透明 一个 设计上问题,大家帮忙提点意见 大哥帮帮小弟吧!在线等候(急)!Vector问题! 请问print和println有什么不同? 如何获得系统时间,类型为java.sql.Timestamp 各位前辈,小弟初学java,能不能推荐一些书啊? 菜问题(请救命啊)
* @author Soloist
* @author http://www.soloist.com
* @version 1.0
*/
import java.io.*;public class FileWriterTest{
public static void main(String[] args){
int people;
int[] chinese,english,math;
File filePath;
BufferedWriter bufout;
InputStreamReader stdin=new InputStreamReader(System.in); //键盘输入
BufferedReader bufin=new BufferedReader(stdin);
try{
System.out.println("======简易成绩单======");
System.out.print("请输入人数:");
people=Integer.parseInt(bufin.readLine());
System.out.println("请输入成绩存盘路径:");
filePath=new File(bufin.readLine());
bufout=new BufferedWriter(new FileWriter(filePath));
chinese=new int[people];
english=new int[people];
math=new int[people];
for(int i=0;i<people;i++){
System.out.println((i+1)+"号");
System.out.print("语文:");
chinese[i]=Integer.parseInt(bufin.readLine());
System.out.print("英文:");
english[i]=Integer.parseInt(bufin.readLine());
System.out.print("数学:");
math[i]=Integer.parseInt(bufin.readLine());
}
System.out.println("已完成登记所有成绩!");
System.out.println("=========打印成绩单到"+filePath.getPath()+"=========");
for(int i=0 ;i<people;i++){
bufout.write((i+1)+"号 语文:" + chinese[i]);
bufout.write(" 英文:"+english[i]);
bufout.write(" 数学:"+math[i]);
bufout.newLine();
bufout.flush(); //写入文件,经过我的测试,不加flush()函数一样可以写入数据
}
stdin.close();
bufin.close();
bufout.close();
}
catch(IOException E){
System.out.println("发生I/O错误!");
}
}
}
infor.setLineWrap(true);//让Area自动换行
out是 FileWriter
out.write("内容");
out.newLine();//换行
搞定!
/******************** WriteFile.java ********************/
import java.io.*;
public class WriteFile
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(
new FileWriter("line.txt"));
String s;
while (true)
{
System.out.print("块﹃: ");
System.out.flush();
s=br.readLine();
if (s.length()==0) break;
bw.write(s);
bw.newLine();//这句就是换行的
}
bw.close();
}
}
Unix/Linux中的回车是"\n"
OS/2中的回车版本是"\r"
如果乱来,在Windows中的记事本里只能是"黑方格",但用ultraedit打开这个txt,就没有了