special escape sequences
文檔
The Java programming language also supports a few special escape sequences for char and String literals:
\b ( backspace) , \t ( tab) , \n ( line feed) , \f ( form feed) , \r ( carriage return) , \" ( double quote) , \' ( single quote) , and \\ ( backslash) .
應用
private void createFile ( String data) {
ReturnReceiveBody receiveBody= gson. fromJson ( data, ReturnReceiveBody. class ) ;
XStream xStream= new XStream ( new Xpp3Driver ( new NoNameCoder ( ) ) ) ;
xStream. autodetectAnnotations ( true ) ;
String content= xStream. toXML ( receiveBody) ;
content= content. replaceAll ( "(?<=>)\\s+(?=<)" , "" ) . replaceAll ( "\\r\\n" , "" ) . replaceAll ( "
" , "" )
. replaceAll ( ">" , "" ) ;
FileUtils fileUtils= new FileUtils ( ) ;
String fileName= UUID. randomUUID ( ) . toString ( ) + genRandomNum ( 8 ) ;
buffer. append ( content) ;
buffer. append ( "\r\n" ) ;
num. addAndGet ( 1 ) ;
if ( num. get ( ) == total. get ( ) ) {
boolean flag= fileUtils. writeFile ( fileName, buffer. toString ( ) , filePath) ;
if ( ! flag) {
LOGGER. info ( "文件保存失敗" ) ;
} else {
LOGGER. info ( "文件保存成功" ) ;
}
num. getAndSet ( 0 ) ;
buffer. setLength ( 0 ) ;
}
}