2017-04-13 60 views
0

打印出當我打印出的問題[0]到一個TextArea,輸出看起來像這樣:字符串數組(字符串[])是在單個線儘管的println

Line1Line2

我所要的輸出看起來像這樣:

一號線

2號線

儘管使用println如何更改輸出格式?

驗證碼:

public void run() { 
     try { 
      write = new PrintStream(connection.getOutputStream()); 
      //Skriva till klienten. 
      List<String> questionsList = new ArrayList<>(); 

      try (Stream<String> questionsStream = Files.lines(Paths.get(quizFile))) { //Reading from text file 
       questionsList = questionsStream 
         .parallel() 
         .collect(Collectors.toList()); 
       Collections.shuffle(questionsList); //Randomizing the Strings. 

       while (true) { 

        for (String string : questionsList) { 
         String[] questions = string.split("/"); 
         write.println(questions[0]); //Printing out [0]."\n" does not seperate the String to seperate lines. 
         try { 
          Thread.sleep(4000); //"Sleeping" between the lines. 
         } catch (InterruptedException e) { 
          e.printStackTrace(); 
         } 
        } 
+1

這看起來像是客戶端的問題。您應該顯示接收方。如果文本顯示爲HTML,則在每行後面添加'
', – Axel

+1

'questionsList'中的strs是否帶有帶'/'符號的文本? –

+0

@Axel:OP說這是輸出到'textarea';如果是這樣,換行符就足夠了。使用'
'實際上會將文本'
'放在'textarea'中。 –

回答

0

你應該使用HTML,中write.println(questions[0] + "<br>");標籤 '
'。

+0

不,OP說這是輸出到'textarea';如果是這樣,換行符就足夠了。使用'
'實際上會將文本'
'放在'textarea'中。 –