输出流,JTextArea中字符串写入文本文件中的换行问题

wzy9645 2002-03-31 05:56:17
直接用bufferedwriter写入文本文件中换行如何判断和设置
...全文
395 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzy9645 2002-04-04
  • 打赏
  • 举报
回复
问题关键就在这呀
chrischen79 2002-04-02
  • 打赏
  • 举报
回复
不知道,关键问题是从JTextArea获得的用户输入String中区分出换行符,你如果不想逐个检查char,就要想一个更高效的方法,我不知道。
wzy9645 2002-04-01
  • 打赏
  • 举报
回复
chenyuan_tongji(chenyuan_tongji) 这种写法我也想过,会不会影响速度?没有更好的办法了吗?
类似readLine()方法的。
松耦合紧内聚 2002-03-31
  • 打赏
  • 举报
回复
String buffer;
String s=BufferedReader.readLine();
while(s!=null)
{
buffer=buffer+"\n";
s=BufferedReader.readLine();
}
类似于此
chrischen79 2002-03-31
  • 打赏
  • 举报
回复
void jButton1_actionPerformed(ActionEvent e) {
String s = jTextArea1.getText();
FileWriter fw = null;
PrintWriter pw = null;
try{
fw = new FileWriter("output.txt");
pw = new PrintWriter(fw);

for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if( c != 10 ){
pw.print(c);
}else{
pw.println();
}
}

}catch(java.io.IOException ioe){
ioe.printStackTrace();
}finally{
try{
if( pw != null ) pw.close();
if( fw != null ) fw.close();
}catch(java.io.IOException ignore){
}
}

}
wzy9645 2002-03-31
  • 打赏
  • 举报
回复
up
wzy9645 2002-03-31
  • 打赏
  • 举报
回复
是想用\n的。不知道怎么做。
GJA106 2002-03-31
  • 打赏
  • 举报
回复
用\n来判断不行吗,

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧