Json是在程序编辑中经常使用的一种格式,它使用起来还是很方便的,那在实际开发中,json数组怎么换行拼接符?接下来我们就来给大家讲解一下json数组换行拼接符的相关方法。
Js中经常会使用JSON,则可以用如下方式,正则匹配字符串中的所有换行符,进行替换
Data = Data.replace(/\n/g, "\\\\n");//

若是换行符不重要也可以直接去掉。

java如何读取文件换行?
1. Java读取txt文件
package com.campu;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
/**
* H20121012.java
*/
public class H20121012
{
public static void readTxtFile(String filePath)
{
try
{
String encoding = "GBK";
File file = new File(filePath);
if (file.isFile() && file.exists())
{ //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding); //考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null)
{
System.out.println(lineTxt);
}
read.close();
}
else
{
System.out.println("找不到指定的文件");
}
}
catch (Exception e)
{
System.out.println("读取文件内容出错");
e.printStackTrace();
}
}
public static void main(String argv[])
{
String filePath = "L:\\Apache\\htdocs\\res\\20121012.txt";
// "res/";
readTxtFile(filePath);
}
}2.不同操作系统换行写txt文件
针对常用的系统,可以使用如下的转义符实现换行:
windows下的文本文件换行符:\r\n
linux/unix下的文本文件换行符:\r
Mac下的文本文件换行符:\n
(1).使用java中的转义符"\r\n":
String str="aaa";
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();
json数组换行拼接符还是很简单的,大家可以参考以上方法,另外,java读取文件换行也是大家需要掌握的点,掌握这些可以提高大家在开发中的工作效率。最后大家如果想要了解更多json工具教程知识,敬请关注奇Q工具网。
推荐阅读:
editplus注册激活码多少?EditPlus有哪些功能?