title: How to print out a line in a textfile into 2 different lines on console Java
body: <pre><code>public static FAQ_Alisa_QnA[] oipReadQuestion(){
          String questionA1,thisUser;
          int indexQuestion;
          String [] entryDetails;
          FAQ_Alisa_QnA [] entries = new FAQ_Alisa_QnA[100];
          //Read file = "activities.txt".
          File file = new File ("ReadOIP.txt");
          int count = 0;
  
          try{
              Scanner sc = new Scanner(file);
              //do this while there is a next line in file.
              while(sc.hasNextLine()){
                  String line = sc.nextLine();
                  entryDetails = line.split(";");
  
                  //              index = entryDetails[0];
  
                  indexQuestion = Integer.parseInt(entryDetails[0]);
                  thisUser = entryDetails[1];
                  questionA1 = entryDetails[2];
  
  
                  //Object to store values of entry.
                  FAQ_Alisa_QnA a = new FAQ_Alisa_QnA();
  
                  //              a.index = Integer.parseInt(index);
                  a.indexQuestion = indexQuestion;
                  a.thisUsername = thisUser;
                  a.questionA1 = questionA1;
  
                  entries [count] = a;
                  count++;
              }
          }catch(FileNotFoundException fnfe){
              System.out.println(fnfe.getMessage());
          }
          FAQ_Alisa_QnA [] allQuestions = new FAQ_Alisa_QnA [count];
  
          for(int i = 0; i &lt; count; i++){
  
              allQuestions[i] = entries[i];
          }
          return allQuestions;
      }
      public static FAQ_Alisa_QnA[] oipReadAnswers(){
          String indexAnswer, answer11, thisUser;
          String [] answerDetails;
          FAQ_Alisa_QnA [] answers = new FAQ_Alisa_QnA[100];
          //Read file = "activities.txt".
          File thisFile = new File ("AnsReadOIP.txt");
          int count1 = 0;
  
          try{
              Scanner sc1 = new Scanner(thisFile);
              //do this while there is a next line in file.
              while(sc1.hasNextLine()){
                  String line = sc1.nextLine();
                  answerDetails = line.split(";");
  
                  //              index = entryDetails[0];
                  indexAnswer = answerDetails[0];
                  thisUser = answerDetails[1];
                  answer11 = answerDetails[2];
  
  
                  //Object to store values of entry.
                  FAQ_Alisa_QnA a = new FAQ_Alisa_QnA();
  
                  //              a.index = Integer.parseInt(index);
  
                  a.indexAnswer = Integer.parseInt(indexAnswer);
                  a.thisUsername = thisUser;
                  a.answer11 = answer11;
  
                  answers [count1] = a;
                  count1++;
              }
          }catch(FileNotFoundException fnfe){
              System.out.println(fnfe.getMessage());
          }
          FAQ_Alisa_QnA[] allAnswers = new FAQ_Alisa_QnA[count1];
  
          for(int i = 0; i &lt; count1; i++){
  
              allAnswers[i] = answers[i];
  
          }
          return allAnswers;
      }
      public static void oipPrintQnA(){
  
          FAQ_Alisa_QnA [] allQuestions   =  oipReadQuestion();
          FAQ_Alisa_QnA [] allAnswers = oipReadAnswers();
  
  
          System.out.println("Organization in project work");
          System.out.println("=============================");
          for(int i = 0; i &lt; allQuestions.length; i++){
              System.out.println( allQuestions[i].indexQuestion + "-" + "Question" + ":");
              System.out.println(allQuestions[i].thisUsername + ":" +allQuestions[i].questionA1);
              System.out.println("                ");
              for(int j = 0; j &lt; allAnswers.length; j++){
                  if(allQuestions[i].indexQuestion == allAnswers[j].indexAnswer){
                      System.out.println("Answer for question "+ + allAnswers[j].indexAnswer+ ":" );
                      System.out.println(allAnswers[j].thisUsername+ ":" +allAnswers[j].answer11);
                      System.out.println("                ");
  
                  }
              }
          }
  
      }
  </code></pre>
  
  <p>//So I have read answers and questions and I saved my qns and answers in 2 different text files. This is because I have add functions to it but i never put it here cuz my qn is not related to that. I just wanna know how to print out the qn and answer in 2 lines so that if the qn is so long then it can print out in two lines//</p>
  
  <p>So these are how my text files look like:
  ReadOIP.txt</p>
  
  <p>1;Shafiq;How to organize your time well when you're juggling with so many project work and assignments on the same day? Best answer:The best solution to this is to early planning or schedule your time wisely. Write in a calendar beforehand  the work you are going to do for an assignment.
  2;Rohannah;Does having a timetable works to finish your project on time?
  3;lymeoww;Is task allocation really important to be organized in project work?</p>
  
  <p>AnsReadOIP.txt</p>
  
  <p>1;Andy23;The best solution to this is to early planning or schedule your time wisely. Write in a calendar beforehand  the work you are going to do for an assignment .2; Does having a timetable to do your project works? <em><a href="http://i.stack.imgur.com/0nPl2.png" rel="nofollow"><strong>//For example this line, it will print out very long on the console//</strong></a></em>
  2;Betty23;of course it does!
  1;Ying Qian;just organize lorh
  3;lymeoww;Yes, it is important!</p>
  
  <p>//Refer to this picture//</p>