轉義字符

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("&#xd", "")
                .replaceAll("&gt;", "");

        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("文件保存成功");
            }
            // 置0
            num.getAndSet(0);
            buffer.setLength(0);
        }

    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章