0

I'm trying to convert these lines into C#, but I'm struggling. Mainly with InputStreamReader and BufferedReader lines.

private static void runPrompt() throws IOException {
    InputStreamReader input = new InputStreamReader(System.in);
    BufferedReader reader = new BufferedReader(input);

    for (;;) { 
      System.out.print("> ");
      String line = reader.readLine();
      if (line == null) break;
      run(line);
    }
}

private static void run(String source) {
    Scanner scanner = new Scanner(source);
    List<Token> tokens = scanner.scanTokens();

    // For now, just print the tokens.
    for (Token token : tokens) {
      System.out.println(token);
    }
}

1 Answer 1

1

The equivalent of an InputStreamReader in C# is a System.IO.StreamReader. There is - AFAIK - no direct equivalent to a BufferedReader in C#. There is BufferedStream, but that is for byte-oriented streams, not character-oriented. However, StreamReader itself can be configured with a buffer through one of its constructors (i.e. StreamReader(Stream, Encoding, Boolean, Int32).

Another way to look at it is that a C# StreamReader combines the functionality of Java's InputStreamReader (conversion from byte-oriented to character-oriented) and BufferedReader (buffering, reading lines).

Sign up to request clarification or add additional context in comments.

1 Comment

I will be doing an byte-oriented system so BufferedStream should be thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.