j2me 中的 System.getProperty("line.separator") 等效项

发布于 2024-12-29 05:50:31 字数 241 浏览 1 评论 0 原文

我需要有一个跨平台换行符引用来解析文件,并且我正在尝试找到一种方法来执行与通常的

System.getProperty("line.separator"); 等效的操作,

但尝试在 J2ME 中,我得到一个 null String 返回,所以我猜测 line.separator 不包含在这里。还有其他直接方法可以在 J2ME 中将通用换行序列作为字符串获取吗?

编辑:稍微澄清了问题

I need to have a cross-platform newline reference to parse files, and I'm trying to find a way to do the equivalent of the usual

System.getProperty("line.separator");

but trying that in J2ME, I get a null String returned, so I'm guessing line.separator isn't included here. Are there any other direct ways to get a universal newline sequence in J2ME as string?

edit: clarified question a bit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼亦尘 2025-01-05 05:50:31

好像忘记回答我的问题了。我使用了一段代码,允许我使用“\r\n”作为分隔符,并且实际上也分别考虑了 \r 和 \n:

public class Tokenizer {
   public static String[] tokenize(String str, String delimiter) {

       StringBuffer strtok = new StringBuffer();
       Vector buftok = new Vector();

       char[] ch = str.toCharArray();                       //convert to char array
       for (int i = 0; i < ch.length; i++) {

           if (delimiter.indexOf(ch[i]) != -1) {   //if i-th character is a delimiter               
               if (strtok.length() > 0) {
                   buftok.addElement(strtok.toString());
                   strtok.setLength(0);
               }
           } 
           else {
               strtok.append(ch[i]);
           }
       }

       if (strtok.length() > 0) {
           buftok.addElement(strtok.toString());
       }


       String[] splitArray = new String[buftok.size()];
       for (int i=0; i < splitArray.length; i++) {
           splitArray[i] = (String)buftok.elementAt(i);
       }
       buftok = null;

       return splitArray;
   }
}

Seems like I forgot to answer my question. I used a piece of code that allowed me to use "\r\n" as delimiter and actually considered \r and \n as well seperately:

public class Tokenizer {
   public static String[] tokenize(String str, String delimiter) {

       StringBuffer strtok = new StringBuffer();
       Vector buftok = new Vector();

       char[] ch = str.toCharArray();                       //convert to char array
       for (int i = 0; i < ch.length; i++) {

           if (delimiter.indexOf(ch[i]) != -1) {   //if i-th character is a delimiter               
               if (strtok.length() > 0) {
                   buftok.addElement(strtok.toString());
                   strtok.setLength(0);
               }
           } 
           else {
               strtok.append(ch[i]);
           }
       }

       if (strtok.length() > 0) {
           buftok.addElement(strtok.toString());
       }


       String[] splitArray = new String[buftok.size()];
       for (int i=0; i < splitArray.length; i++) {
           splitArray[i] = (String)buftok.elementAt(i);
       }
       buftok = null;

       return splitArray;
   }
}
甜心小果奶 2025-01-05 05:50:31

我不认为“line.separator”是JME的系统属性。请参阅面向 MIDP 开发人员的 SDN 常见问题解答中的此文档:定义的 J2ME 系统属性是什么名称?

为什么你仍然需要获取行分隔符?我知道你可以在 JME 中使用“\n”。

I don't think "line.separator" is a system property of JME. Take a look at this documentation at SDN FAQ for MIDP developers: What are the defined J2ME system property names?

Why do you need to get the line separator anyway? What I know is that you can use "\n" in JME.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文