mysql line separator_java输出换行的标准姿势line.separator
java中寫.txt文件,實現換行的幾種方法:
1.使用java中的轉義符"\r\n":
windows下的文本文件換行符:\r\n
linux/unix下的文本文件換行符:\r
Mac下的文本文件換行符:\n
1.String str="aaa";
2.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");
bw.newline();
/**
* Creates a new buffered character-output stream that uses an output
* buffer of the given size.
*
* @param out A Writer
* @param sz Output-buffer size, a positive integer
*
* @exception IllegalArgumentException If sz is <= 0
*/
public BufferedWriter(Writer out, int sz) {
super(out);
if (sz <= 0)
throw new IllegalArgumentException("Buffer size <= 0");
this.out = out;
cb = new char[sz];
nChars = sz;
nextChar = 0;
lineSeparator = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
}
BufferedWriter中newline()方法:
/**
* Writes a line separator. The line separator string is defined by the
* system property line.separator, and is not necessarily a single
* newline ('\n') character.
*
* @exception IOException If an I/O error occurs
*/
public void newLine() throws IOException {
write(lineSeparator);
}
3.使用System.getProperty()方法:
String str = "Output:"+System.getProperty("line.separator");
http://www.cnblogs.com/todoit/archive/2012/04/27/2473232.html
PrintWriter在以下以pw代替,在寫client與server進行測試的通訊程序時,用pw.println(str)可以把數據發送給客戶端,而pw.write(str)卻不行!
查看源碼發現:
pw.println(str)方法是由write方法與println()方法組成,而println()方法中執行了newLine()方法。
而 newLine()實現中有一條out.write(lineSeparator);
即println(str)方法比write方法中多輸出了一個lineSeparator字符;
其中lineSeparator實現為:
lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
而line.separator屬性跟據每個系統又是不一樣的。
println()方法的注釋說明中提到:
/**
* Terminates the current line by writing the line separator string. ?The
* line separator string is defined by the system property
* line.separator, and is not necessarily a single newline
* character ('\n').
*/
在我機器上(windows)測試,默認的lineSeparator輸出的十六進制為13 10即\r\n
這樣write方法修改為:write(str+"\r\n")即達到了與println(str)一樣的效果了。
http://blog.csdn.net/vhomes/article/details/6650576
【轉】JAVA輸出內容打印到TXT以及不同系統中如何換行
JAVA輸出內容打印到TXT以及不同系統中如何換行 http://xiyang.09.blog.163.com/blog/static/59827615201172552755293/ 2011-08 ...
Java基礎 println print 實現輸出換行
JDK :OpenJDK-11 ?????OS :CentOS 7.6.1810 ?????IDE :Eclipse 2019?03 typesetting :Markdown ? code ...
java在文件中輸出換行符
在字符串后面添加\r\n就可以了. ? 或者使用newline方法: FileOutputStream fos=new FileOutputStream("c:\\11.txt") ...
Java 輸出文件通過 BufferedWriter.newline() 方法換行
最近項目中需要導出文件,其實導出文件是一個挺簡單的事情.但是卻遇到了很奇怪的問題. 首先導出到文件需要用到 BufferedWriter.而換行則是通過?bw.newline()?方法,問題將出在?n ...
使用System.getProperty(";line.separator";)時沒有換行問題解決
項目中要實現替換模版txt文本里面的內容,然后生成新的文檔,其中先把模版文本的內容通過創建的?BufferedReader bufReader 使用 readLine() 來一行一行讀取,所以在完成替 ...
java 讀入換行
java中實現換行有以下幾種方法:1.使用java中的轉義符"\r\n":?注意:\r,\n的順序是不能夠對換的,否則不能實現換行的效果. 2.BufferedWriter的new ...
java寫入換行符
寫入一個文件,生成文本文檔,里面寫入1000行字符,但是寫出來的沒有換行.所以糾結,百度了下,一行完事. String crlf=System.getProperty("line.separ ...
【python】禁止print輸出換行的方法
print后用一個逗號結尾就可以禁止輸出換行,例子如下 >>> i=0 >>> while i < 3: print i i+=1 0 1 2 禁止輸出換行后 ...
隨機推薦
Flex 加載 wmf,svg
最近做gis系統發現要在flex加載wmf圖片.我記得flash的loader只能是png,gis,jpg.wmf格式居然是window出的,flash居然不支持我也是醉了,沒辦法,只能后臺轉格式,首 ...
PLSQL_監控有些SQL的執行次數和頻率
原文:PLSQL_監控有些SQL的執行次數和頻率 2014-12-25 Created By 鮑新建
[模擬賽] T3 最優序列
Description 給出一個長度為n(n<=1000)的正整數序列,求一個子序列,使得原序列中任意長度為m的子串中被選出的元素不超過k(k<=m<=10)個,并且選出的元素之和最 ...
1.docker常用命令
1.啟動交互式容器 $ docker run -i -t IMAGE /bin/bash -i --interactive=true|false 默認是false -t --tty=true|fals ...
Git使用詳細教程(4):git rm使用詳解
我們使用git rm 文件名來進行刪除文件的操作. git rm index.php這個命令把工作區的index.php刪除并暫存了. 如何撤回已暫存的刪除命令? 上圖中已經給出了提示,使用git r ...
獲取linux服務進程號
ps -ef | grep "服務名" | grep -v "grep" | awk '{print $2}' #?ps -ef|grep "被查詢的 ...
DataTableHelper
public class DataTableHelper { /// /// 給DataTable增加一個自增列 /// 如果DataTable 存在 identity ...
前端學習 -- Css -- 默認樣式
瀏覽器為了在頁面中沒有樣式時,也可以有一個比較好的顯示效果, 所以為很多的元素都設置了一些默認的margin和padding,而它的這些默認樣式,正常情況下我們是不需要使用的. 所以我們往往在編寫樣式 ...
打開指定目錄路徑的CMD命令行窗口
1.打開目錄文件夾, Shift + 右鍵 2.會直接打開CMD所在的目錄路徑
eclipse的.properties文件中文顯示問題
eclipse的.properties文件,默認的編碼方式是iso-8859-1. 所以中文顯示有問題. 按照下面的方式,把Default Encoding修改成UTF-8就可以了.
總結
以上是生活随笔為你收集整理的mysql line separator_java输出换行的标准姿势line.separator的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# PictureBox设置图片
- 下一篇: duid 配置监控