0

Im writing a program in Eclipse IDE that reads text from a file and converts the text to a sequence of numbers. The code I've written worked, as I've seen the console output before, but suddenly the console has stopped outputting anything.

Is there a setting I can change to get this working again? Or do you notice as issue with the code that would cause no output in the console?

I'm stuck with this and just want to move past it thank you!

package poetry;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class POETRY {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
                
                try {
                    File x = new File("/Users/jordanBendon/Desktop/Cypher/poem.txt");
                    Scanner sc = new Scanner (x);
                    Scanner scnr = new Scanner(x);
                    
                    while(scnr.hasNextLine()) {
                        String lines = scnr.nextLine();
                        
                        char[] stringArray = lines.toCharArray();
                        
                        String result = "";
                        
                          for (int i = 0; i < lines.length(); i++) {
                            int ascii = lines.codePointAt(i);
                            if ((ascii >= 65 && ascii <= 90) || (ascii >= 97 && ascii <= 122)) {
                              ascii += 15;
                              result += Integer.toString(ascii);
                            } else {
                              result += stringArray[i];
                            }
                          }
                          System.out.println(result);
                        };
                }
                catch (Exception e) {
                    System.out.println("error");
                }
    }
                
    
}
  • Welcome to SO, i provided an answer to your question please consider to accept and upvote if it satisfied your requirement otherwise feel free to leave comment, how ever i suggest yo have brief look as well in https://stackoverflow.com/help/how-to-ask . – Lunatic May 22 '22 at 08:11
  • Note: Java Strings are Unicode, not Ascii, so your variable name `ascii` is misleading. – greg-449 May 22 '22 at 09:01

2 Answers2

1

The isn't any problem with code (with assuming that you mentioned path for File x is valid), in the code you printing the result in line System.out.println(result); If your input file is being empty then noting will append to result and for loop will not be triggered consequently nothing will be shown in output console, which it is the case that you currently experiencing it.

Lunatic
  • 1,519
  • 8
  • 24
0

As per what I understood, your code is not writing full result on console.

So, I think this might be a problem because of limit console output feature of Eclipse.

follow below solution to increase "console output limit" so that you can get full output on console. solution -> https://stackoverflow.com/a/2828287/19172498

  • Hey @KishorMandve, thanks for your response. I think this may be the problem. However Im struggling to find the console output limit in my Eclipse as this question is from 2010 and I think the navigation to these settings has changed since then.. – CoderInNeed May 22 '22 at 14:08
  • For Eclipse 2022-03 the settings are in the same place as the posted answer suggests. Check under `Run configurations` that the launcher for that task has `Allocate console` checked. – LMC May 22 '22 at 17:13