【问题标题】:Writing a String on a new line在新行上写一个字符串
【发布时间】:2018-03-21 15:19:00
【问题描述】:

尝试将字符串写入文件中的新行,虽然我在字符串末尾添加了“\n”但无法成功代码如下:-

Timer t = new Timer();

                t.scheduleAtFixedRate(new TimerTask() {
                    @Override
                    public void run() {
                        for (;true;){
                        String smsg = new String("$;TRIG;");
                        String neuline= "";
                        neuline =neuline +"\n";
                            neuline =smsg+"\n";
                        activeBT.write(neuline.getBytes());
                    }}
                }, 0, 100);

谁能帮帮我

【问题讨论】:

标签: java android string bluetooth newline


【解决方案1】:

你可以这样解决:

activeBT.write(smsg+System.getProperty("line.separator"));
activeBT.write();

【讨论】:

    【解决方案2】:

    我用字节数组解决了:

    byte[] mybyte= new byte[] {'$',';','T','R','I','G',';',13,10};
    activeBT.write(mybyte);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-14
      相关资源
      最近更新 更多