How to reassign standard input stream

Hello, i have a problem where i need to prompt the user to enter data into the console window (1 line) and read from the console. I wrap the System.in in a BufferedReader like this:
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String inputStr = br.readLine();
while (inputStr != null){
//read from console
Now the problem is that if the user hits CTRL + Z (on Windows) the InputStream becomes null.
Further down in the method I need to once again prompt the user to enter data in the Console but this time invoking the bufferedReader.readLine() always returns null (and does not even block).
The JavaDocs say that this method returns null once end of stream has been reached.
I tried re-setting the System.in by calling
System.setIn(System.in);
but that does not give me what I am looking for.
Any ideas on how I can get to read from the console once CTRL+Z has been entered?
Thanks:
-Sam

In the future, Swing related questions should be posted in the Swing forum.
I don't understand the question. You have the code that adds text from an OutputStream to a JTextArea. You must have copied the code from somewhere, so I'm sure whereever you copied the code from would also show you how to use the code.
Otherwise you can search the Swing forum. There are plenty of example showing how to use a JTextArea as a "console".

Similar Messages

  • How to get file input stream from the client machine by JSF Fileupload API?

    Dear Friends,
    How to get the file input stream from the client machine by JSF HtmlFileupload or fileupload API. At present, if i execute the file upload code in the client machine, it is able to get the local path of the file and looking for the file in server machine. So i am getting FileNotFoundException.
    E.g., If a file is located at client machine at following location means "C:\Test\Test.txt",
    uploadClass.getFileuploadComponent().getFilename().toString() returns "C:\Test\Test.txt". But it is looking for that file in server and throwing FileNotFoundException.
    Please post your replies soon.
    Thanks,
    JP

    Depends on which version of JSF you're using. If JSF 1.2, I wouldn't even bother trying to hack this into JSF itself unless you can use something like Seam 2 or richfaces.
    http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_fileUpload.html
    http://docs.jboss.org/seam/2.2.1.CR3/reference/en-US/html/controls.html#d0e29259 (look for s:fileUpload)
    But if I were you, a simple non-jsf form with a servlet works best for taking file uploads.
    As for JSF 2.0, there are other ways of getting it done.
    http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html

  • How to use standard Search Input Help (return 2 data code and desc) ?

    Hi,
    Please advise how to use standard Input Help provided by SAP and return 2 data (code and description) ? because the standard Input Help only return the code only ?
    Thank You and Best Regards
    Fernand

    >
    Saket  Abhyankar wrote:
    > Hi,
    >
    > I think you need to go for 'Search Help Exit' or OVS.
    >
    > Regards,
    >
    > Saket.
    That is not true that this is the only way.  The standard Data Dictory based search help can return more than one value as long as there are multiple exporting values defined in the search help, the search help is attached to a Data Dictionary Structure, and this same data dictionary structure is used as the source of the context node. You can read more about this in the online help:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/9f724642314aabe10000000a42189b/frameset.htm
    The Note section under Integration:
    If an input help structure is stored in a field in the ABAP Dictionary, and if you want to use the field mapping of search help parameters stored in the ABAP Dictionary as the field name for the structure for your Web Dynpro input help, then map your context nodes to this structure. This ensures that all components of the structure are available dynamically at runtime as attributes of the node.
    If the context node is not mapped to the structure, the data element's input help can be used if there is one.

  • Redirect standard input from file to terminal

    Is there any way to redirect standard input from file to terminal within the same program? That is, get data from a file then redirect standard input to make it interactive with the terminal?

    BIJ001 wrote:
    No, the stdin, stderr, stdout, and working directory are environmental variables that are set
    when your process is launched, and they cannot be changed from within your java application.Can't they?
    //java.lang.System
    public static void setIn(InputStream in)
    //   Reassigns the "standard" input stream.
    public static void setOut(PrintStream out)
    //  Reassigns the "standard" output stream.
    public static void setErr(PrintStream err)
    //  Reassigns the "standard" error output stream.
    Since:
    JDK1.1
    Duh, you're right. I researched this looking for a way to change the working directory and found that you could not change that after launch - for some reason I remembered it wrong as being the stderr, stdin, and stdout in addition.

  • How to get input stream of other application

    Using Java is their any way to get the input stream of another applicaton?. For example i will start a java program and minimize it. Then i will start a notepad and type some thing in it. Java program should print all matters i am typed in notepad.
    Is it possible using java?
    Thanks in advance

    You have many ways to do that in C++. Read about Hooks and you will understand how u can do that. Anyway, even without hooks, u can get the messages from other applications in C++. So, let C++ get the data from other applications for you and let ur java program get data from the C++ program.

  • How to read a file as an input stream after it's posted in an HTML form ?

    Hello,
    I want to read client file after it's posted in an HTML form. But, I don't want to upload it to filesystem or database. I want to read posted file as an input stream. How can I do that ?
    thanks in advance...

    A couple of things. If you have a FILE field in your form, the enctype of the form must be multipart/form-data. Check this link
    http://www.htmlhelp.com/reference/html40/forms/form.html
    Also, when a file is uploaded you cannot use the regular methods to get at the name/value pairs or the file itself. You'll have to use a utility like MultiPartRequest or write your own based on the RFC for Multipart requests.
    http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html
    You will need some temporary file system to store this and then delete it when you are done with it.
    hth

  • How to make use of the Input Stream

    Hai,
    I want to read input from the user for non-character type through Keyboard as the standard input device. How can I read the non-character type. I tried the following method, but not succeeded. The input data may be of type double or int. Can anyone help me.
    DataInputStream num=new DataInputStream(System.in);
    Double Vig_Fair_Value=num.read();
    Thanks,
    Sennat

    You read the characters the user types, eg. "15" into a string using a BufferedReader, you then convert them to a number here's an method to do it for integers
           public static int inInt()
              BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
              String s = "";try{s = inp.readLine();}catch(Exception e){}
              return toInt(s,0);     // make integer, default 0
           public static int toInt(String s, int er)
                int i;
                try{i = new Integer(s).intValue();}
                catch(NumberFormatException exc){i =er;}
                return i;

  • Hi freiends --  to know how to convert an OuputStream to an Input Stream

    I am using generating reports thru IReports and i am trying to convert an ouput received from a .jrxml file into an .pdf file This is how my code goes.
    System.out.println("inside ReportGenerator()");
              InputStream bais = new ByteArrayInputStream(input.getBytes());
              JasperCompileManager.compileReportToStream(bais,out);
              bais = new ByteArrayInputStream(out.toString().getBytes());
    // i am gtting an error over here it say unable to load an input stream.
              JasperFillManager.fillReportToStream(bais,out,new HashMap(),con);
              bais = new ByteArrayInputStream(out.toString().getBytes());
              JasperExportManager.exportReportToPdfStream(bais,out);
    could anyone plz help me

    InputStreams and OutputStreams are not interchangeable, or even particularly convertible. They do inherently different things.
    Sometimes it's possible to string them together, but it's not even clear from your code whether that's appropriate for your problem.
    Probably you should be creating a whole new output stream, completely separate from the input stream. But who knows; you didn't explain what you're trying to accomplish.

  • How to Read from Standard Input?

    Hi,
    I am new to Java. Been reading the tutorial, but still unable to find How to read from standard Input.
    Can anyone help? Thanks.
    Here is my simple & error code:
    public class test
    public static void main(String[] args)
    char filename[];
    int i=0;
    System.out.print("Type in a filename to read: ");
    while ( System.in(filename) != -1 )
    i++;
    System.out.print(filename);
    RP

    import java.io.*;
    public class forum{
         public static void main(String args[]) throws IOException
    InputStreamReader is = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(is);
    String input = "";
    do
    try
    System.out.println("Enter command: ");
    input = br.readLine();
    catch ( IOException io ) {}
    } while (!input.equals("exit"));
    [code\]
    package to import is java.io.*;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Standard input - main(String[] args) -- how?

    In eclipse, how do I feed the main with values?
    public static void main(String[] args) {
           System.out.println("Enter value: ");
           args =
        if (args.length != 1) {
    ...Thanks,
    george

    You mean basically command line arguments?
    Look in the run menu. For every run event there's a form that specifies how to invoke the program. Somewhere in there you can specifiy the command line arguments. I can't recall right now but I can look it up if you can't find it.
    Standard input is a completely different thing from command line arguments. Standard input, from the java point of view, is what comes in on System.in.

  • How do I return an input stream from a text file

    Suppose there's a class with methods..
    one of the methods is something like..
    public int value() and has a return statement at the end obviously for returning an int value..
    Another method reads a text file and creates an input stream..
    Scanner data  = new Scanner(new File(input.next()));
    I want to return the data when I do a call to this method, but I'm not sure what the method heading would look like..

    flounder wrote:
    Are we supposed to magically know what those errors are? Do you think that copying and pasting the exact error messages and indicating the lines they occur on would be useful to us?Sorry about that..
    I've replicated the same code below; and put the number of the line where the error is.
    +cannot find symbol variable read     [line 21]+
    +cannot find symbol variable read     [line 23]+
    +cannot find symbol variable read     [line 29]+
    +cannot find symbol variable read     [line 31]+
    +cannot find symbol variable inputStream     [line 44]+
    +calculate() in textInput cannot be applied to (java.util.Scanner)     [line 57]+
    the reason I have the _______ for the createInputStream() method is because I'm not really sure what the heading type should be to return the input stream.
    import java.io.*;
    import java.util.*;
    public class textInput
              public void requestFileName()
                   Scanner input = new Scanner(System.in);
                   System.out.print("Enter file name: ");
              public _______ createInputStream() throws FileNotFoundException
                   Scanner input = new Scanner(System.in);
                   Scanner read = new Scanner(new File(input.next()));
                   return read;
              public void calculate() throws IOException
    21           double max;
                   double min;
    23            int count = 0;
                   double total = 0;
                   if (read.hasNextDouble())
                        double temp = read.nextDouble();
    29                 max = temp;
                        min = temp;
    31                 count++
                        total += temp;
                        while (read.hasNextDouble())
                             double current = read.nextDouble();
                             count++;
                             min = Math.min(current, min);
                             max = Math.max(current, max);
                             total += current;
                   System.out.println("Max of: " + max);
                   System.out.println("Min of: " + min);
    44            System.out.println("Average of " + total/count);
              public void close() throws IOException
                   inputStream.close();
              public static void main(String[] args)
                   textInput run = new textInput();
                   try
    57                 run.requestFileName();
                        run.createInputStream();
                        run.calculate();
                        run.close();
                   catch(FileNotFoundException e)
                        System.out.println("File not found.");
                        System.exit(0);
                   catch(IOException e)
                        System.out.prinln("File not found.");
                        System.exit(0);
    }

  • How to control (the input and output) EXE file after I call it using exec?

    Hi,
    I knew that I can use runtime.exec() to call one EXE file, and this works. But this EXE has two characteristics:
    1. After this exe starts, it asks user to input number such as 1 or 2 onto computer screen, then press return. Then the exe will start the calculation.
    2. after it starts calculation, it prints 3 columns of numbers onto the screen.
    My two questions are:
    1. How to use java to input the number such as 1 or 2 automatically? this EXE can not work like this in DOS command line:
    C:> file.exe parameter
    The parameter is the number such as 1 or 2 that I wanna input.
    2. how to redirect the 3 columns of numbers from computer screen to txt file?
    My colleague can solve these two questions using Mathematica. So I know that definitely there is at least one solution for it. I just can not do it using Java. This wierd exe file bothered me a lot and I really wish that I can get help from someone in java community.
    Thank you!
    Tony

    When you call Runtime.exec, you get a Process object. (I presume something similar happens when you use ProcessBuilder.) Process has methods with names getOutput, getInput, and getError. These correspond to the standard input, standard output, and standard error streams of the spawned process.
    You can read and write to the process on the streams corresponding to input and output that the process writes to the console.
    [add]
    In fact, you should be grabbing and reading the output/error streams anyway, because of the points raised by the Traps article. Google "Java Runtime exec traps" and you'll probably get a link to this JavaWorld article, which describes common Runtime.exec problems and how to solve them.
    Edited by: paulcw on Jun 15, 2010 4:09 PM

  • Set up standard  input in solaris to avoid 256 characters limit.

    I do hava a Console command line application in java, the application run in Solaris. I run the program in a ksh script and the maxumin line size i can read is 256 characters. How can i set up the standard input to avoid this limitation. I need no limit in the input command line as can have command longer that 5000 characters.
    How to reproduce the scenario.
    public static void main(String[] args)
    System.in.read()
    Is there any way i can set up or initialize the standard input to avoid this limitation?
    Thanks in advance.

    This is a limitation of the terminal driver, so even if the shell can accept more characters, the terminal in front of the shell will stick to the limit defined by MAX_CANON. There are two ways to get around this problem:
    1. Put the terminal into raw mode: "stty raw -echo"
    or
    2. Introduce explicit backslash-newline sequences into the input stream. The terminal will trigger on the newline, but the backslash will tell the shell to keep looking for the logical end of the input.

  • How to use standard texts in smartforms

    Hi Friends,
          How to use standard texts in smartforms, ie in scripts we are using standard texts using tr so10.
    thanks in advance,
    regards,
    sharma.

    For long text
    method1
    Create TEXT node- general attributes change text type to include text
    then you can input text name/text object/text id/language
    method2
    create PROGRAM LINE node - use FM READ_TEXT to read it to a internal table
    then use LOOP or TABLE node to display it
    For TEXT module(For foreign language)
    Tr-code:smartforms -- choose Text module(not choose form)--create a text module object
    then enter smartform Create TEXT node- general attributes change text type to text module
    input the text module name which created by above
    btw SO10 is just for Scriptform, in smartforms we use text module to replace SO10

  • Error in external tax system: SAX processing failed on input stream SAX pro

    Hi
    When I was posted in T.Code: FB70,  (Customer Invoice) I am getting below mentioned error.
    Error in external tax system: SAX processing failed on input stream SAX processi.
    I put tick mark on calculate Tax column and select O1(A/R Sales Taxable).
    Pls. help me.
    Thanks
    Ranjith

    Hi Ranjith,
    I also face this problem in Production now.
    Could you kindly share with me how you resolved this issue?
    Thanks,
    Markus

Maybe you are looking for

  • Nano shows in my computer but will not show in devices. tried reset, disable other programs. still no use

    my nano 6th gen shows in windows but does not show under devces. tried everything in the help program but still doesnt show under devices. can drag and drop music into nano from library to top right i pod symbol.

  • Recording Tips & Tricks

    Do you have a creative recording technique you'd like to share? Did placing that vocal microphone inside an empty plastic bucket give your bass a crazy tone? Did you try plucking your guitar strings with a school eraser to round off those high freque

  • Upgraded Mac Mini to 10.8.3 - now i get sound distortion

    I have a 2009 mac mini connected up to a theatre system and a big screen tv. Its been working fine, until I upgraded to 10.8.3 and now the sound is distorted. I've rebooted, killed coreaudiod, removed any extra plugins from /Library/Audio/Plug-Ins to

  • Materialized view fast refresh

    I would like to create a fast refresh materialized view. The query is below. create materialized view dw_v_bal_txn_fast BUILD IMMEDIATE refresh fast as SELECT b.machine_id,nvl(p.promotion_code_id,0)promotion_code_id,p.promotion_code_name ,min(bal_tra

  • Downloading Bank Statements

    I have purchased a Mac Mini MD387B/A. However my Bank only gives me the facility of downloading statements in Excel or pdf. At present I have to download them on my old computer (with microsoft software) and transfer them via flash drive to Numbers o