Home  >  Article  >  Java  >  How to wrap line in java

How to wrap line in java

(*-*)浩
(*-*)浩Original
2019-11-14 11:12:4215749browse

How to wrap line in java

java中实现换行有以下几种方法:

1.使用java中的转义符"\r\n":            (推荐学习:java课程

String str="aaa";
str+="\r\n";

这样在str后面就有换行了.

注意:\r,\n的顺序是不能够对换的,否则不能实现换行的效果。

2.BufferedWriter的newline()方法:

FileOutputStream fos=new FileOutputStream("c;\\11.txt");
BufferedWriter bw=new BufferedWriter(fos);
bw.write("你好");
bw.newline();
bw.write("java");
w.newline();

3.使用System.getProperty()方法:

String str = "aaa"+System.getProperty("line.separator");

The above is the detailed content of How to wrap line in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn