Java读文件修改默认换行符的实现
作者:风夏夜中 时间:2023-11-29 08:24:32
Java读文件修改默认换行符
Java默认换行符是'\n'。但有时数据并不以'\n'进行换行
方法如下
public static void testRead(String confPath) throws IOException {
System.setProperty("line.separator", "/03");
BufferedReader brConf = new BufferedReader(new InputStreamReader(
new FileInputStream(confPath), "UTF-8"));
for (String line = brConf.readLine(); line != null; line = brConf.readLine()) {
System.out.println(line);
System.out.println("----------------");
}
brConf.close();
}
除'/03'外,业务还可能指定'/01'换行。具体使用什么看具体业务。
Java替换换行符
前端录入的信息,有换行符\r\n,后面拿到数据库存储的数据后需要在前端页面上换行予以显示。
String testStr = "换行\r\n换行";
String result = testStr.replaceAll("(\\r\\n|\\n|\\n\\r)","<br/>");
不用\\\\r\\\\n进行替换,如果字段之间包含\r\n则需要这样进行替换。
已经转义的则使用\\r\\n进行字符串替换就可以正常替换成<br/>
来源:https://blog.csdn.net/qq_29940863/article/details/86604449
标签:Java,读文件,换行符
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现网站微信扫码支付
2023-06-18 18:58:19
SpringMVC Interceptor拦截器使用教程
2022-05-11 02:17:22
![](https://img.aspxhome.com/file/2023/8/67098_0s.png)
C#实现回文检测的方法
2022-12-26 22:31:23
FFmpeg Principle分析Out put File 数据结构
2023-02-17 08:26:49
![](https://img.aspxhome.com/file/2023/5/139155_0s.jpg)
Unity 读取文件 TextAsset读取配置文件方式
2023-07-05 12:24:05
C#中调用VB中Inputbox类的实现方法
2023-09-06 18:12:57
Android编程基础之简单Button事件响应综合提示控件Toast应用示例
2023-06-30 16:27:34
![](https://img.aspxhome.com/file/2023/6/137426_0s.jpg)
Android动画之逐帧动画(Frame Animation)实例详解
2023-02-27 06:12:56
Android自定义ListView实现下拉刷新上拉加载更多
2021-08-20 21:17:04
![](https://img.aspxhome.com/file/2023/0/125550_0s.gif)
java实现发送邮箱验证码
2022-07-05 07:40:07
![](https://img.aspxhome.com/file/2023/6/83436_0s.jpg)
Swing图形界面实现可动态刷新的验证码
2022-03-27 08:08:50
国内分布式框架Dubbo使用详解
2022-05-10 13:38:27
![](https://img.aspxhome.com/file/2023/3/71883_0s.jpg)
详细介绍idea如何设置类头注释和方法注释(图文)
2022-05-08 20:22:41
![](https://img.aspxhome.com/file/2023/8/77458_0s.jpg)
从汇编码分析java对象的创建过程(推荐)
2023-06-09 18:05:17
IDEA不识别Java文件:文件变橙色&显示后缀名.java的解决
2022-05-27 06:43:36
![](https://img.aspxhome.com/file/2023/8/118918_0s.png)
Java由浅入深刨析继承
2023-11-23 08:04:24
![](https://img.aspxhome.com/file/2023/4/59564_0s.jpg)
Kotlin Flow操作符及基本使用详解
2022-08-24 16:32:30
![](https://img.aspxhome.com/file/2023/2/137782_0s.jpg)
Java内存模型详解
2023-06-21 21:04:29
![](https://img.aspxhome.com/file/2023/2/57592_0s.webp)
利用C#实现获取当前设备硬件信息
2022-09-11 07:15:37
c# AES字节数组加密解密流程及代码实现
2021-12-11 21:44:20
![](https://img.aspxhome.com/file/2023/7/94537_0s.png)