【问题标题】:System.getProperty("line.separator") Vs "\n" for AndroidSystem.getProperty("line.separator") 与 Android 的 "\n"
【发布时间】:2012-10-20 10:21:34
【问题描述】:

我的疑问是System.getProperty("line.separator")"\n" 用于Android 网络操作是否相同。 我的意思是说。我将从某些服务器获得行分隔的响应,因此使用System.getProperty("line.separator")"\n" 哪个更好?

refred Carriage returns/line breaks with \n in strings in Android 但仍不确定网络操作。

【问题讨论】:

    标签: java android linux httpresponse


    【解决方案1】:

    如果您收到以行分隔的响应,请使用BufferedReader.readLine() 读取每一行,然后如果您想将换行符插入回字符串中,请使用System.getProperty("line.separator")

    【讨论】:

    • 我目前正在以同样的方式进行操作。但我担心的是它System.getProperty("line.separator") 是否会在所有设备上给我相同的响应。
    • System.getProperty("line.separator") 旨在在该设备上向您返回正确的行分隔符。它不会跨设备返回相同的字符。如果它一直返回相同的字符,它的目的就失去了。
    • 你的意思是说BufferedReader.readLine()在内部使用System.getProperty("line.separator")从输入流中读取行。
    • 不完全是。从服务器读取响应时,操作系统的行分隔符无关紧要。只要收到 \r 或 \n,框架就应该解释它并读取该行。来自文档 - A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r')
    猜你喜欢
    • 2016-08-16
    • 1970-01-01
    • 2020-05-16
    • 2011-03-31
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    相关资源
    最近更新 更多