Inputting Text in a java program

How do you input text in a java progerm? Im relearning java at the min. Havnt looked at it since studying it in uni(3 years ago). One problem I am having is that at uni we used a set of API's the uni had created. The problem with this is that I dont have it anymore. With this if I wanted to input some text I did sopmething similar to the following:
uuInOut.readLine();

Have you tried Google? with words like 'Java input"? (Top link gives you an answer :) )

Similar Messages

  • Sorting Names in a text file using java program

    h1. Deleting numbers in a text file, sorting the names  and writing in to a new file
    h2. Sample data
    =================
    71234 RAJA
    89763 KING
    89877 QUEEN
    ==================
    h2. Java Program
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.InputStreamReader;
    import java.io.Writer;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    class Sortnames { 
    public static void main(String args[]) { 
    try { 
    ArrayList storeWordList = new ArrayList();
    ArrayList storeWordList2 = new ArrayList();
                   int i;
    char c;
                   String inputfile = "names_konda.txt";
                   String tempfile = "newdatafile.txt";
                   String outputfile = "sortedoutput.txt";
                   StringBuffer strBuff=null;
    Writer output = null;
    File file =null;
                   Writer sortedoutput = null;
    boolean select =false;
                   //*********************************************** Reading data from Input file     
    FileInputStream fstream = new FileInputStream(inputfile);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) { 
    storeWordList.add(strLine);
    //Close the input stream
    in.close();
                   //*********************************************** Adding only alphabets to buffer and writing to file
                   file= new File(tempfile);
                   output = new BufferedWriter(new FileWriter(file));
    strBuff = new StringBuffer();
    for (Iterator iter = storeWordList.iterator(); iter.hasNext();) { 
         String s = (String) iter.next();
                        //System.out.println("String "+s);
         for (i = 0; i < s.length() ; i++)
    c = s.charAt(i);
    if (Character.isLetter(c)) {
    strBuff.append(c);
                        strBuff.append("\n");
    String myout = strBuff.toString();                
         output.write(myout);
         output.close();
         //============================================== Reading the created file,Sorting and placing in Collections
                   FileInputStream fstream2 = new FileInputStream(tempfile);
    // Get the object of DataInputStream
    DataInputStream in2 = new DataInputStream(fstream2);
    BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    String strLine2;
    //Read File Line By Line
    while ((strLine2 = br2.readLine()) != null) {                 
    storeWordList2.add(strLine2);
    Collections.sort(storeWordList2);
                   //===================================================
    File sortedfile = new File(outputfile);
    sortedoutput = new BufferedWriter(new FileWriter(sortedfile));
    for(int m=0; m<storeWordList2.size(); m++)
         if (storeWordList2.get(m).toString().trim().length() > 0)
              sortedoutput.write(storeWordList2.get(m).toString());
                        sortedoutput.write("\n");     
    sortedoutput.close();
    System.out.println("Names Sorted SUCCESFULLY");
    br.close();
    br2.close();
    in.close();
    fstream.close();
    fstream2.close();
                   ///==========================================
                   File f1 = new File(tempfile);
                   boolean success = f1.delete();
                   if (!success){
                        System.out.println("failed deletion ");
                        System.exit(0);
                        }else{
                        System.out.println("deleted");
                   // ==========================================
    } catch (Exception e) {//Catch exception if any 
    System.out.println("Error: " + e);
    h2. Thanks and regards
    h1. BalaNagaRaju.M
    h1. [email protected]

    Do you have a question? Also see the sticky welcome post on how to post formatted code.

  • Pass the BPEL Input Payload to Embedded Java Program

    Please let me know how can we pass the Input to a BPEL process to the embedded Java Program.
    Requirement:
    To pass the payload recieved by the BPEL process to a Java method using embedded java activity where we can parse/modify this payload
    I tried this approach
    Object obj = (Object)getVariableData('variableName');
    //call to java method with obj as argument
    //In java method
    XMLElement xmlElement = (XMLElement)obj;
    thereafter I am trying to read the nodes of this element but this is not working.
    Please point me to any document/tutorial/examples in this context.
    Thanks

    Hi
    the getVariableData() method returns a org.w3c.dom.Element object (10.1.3 version).
    So I believe you should use something like:
    Object obj = (Object)getVariableData('variableName');
    //call to java method with obj as argument
    //In java method
    org.w3c.dom.Element xmlElement = (org.w3c.dom.Element)obj;
    And to read a node use this:
    org.w3c.dom.Node node = xmlElement.getFirstChild().getNodeValue();
    However I never tried getVariableData('variableName'), I tried getVariableData('variableName','partName','query') so I don´t know the diferences between these two methods, but I hope this helps you.

  • How to read characters from a text file in java program ?

    Sir,
    I have to read the characters m to z listed in a text file .
    I must compare the character read from the file.
    And if any of the characters between m to z is matched i have to replace it with a hexadecimal value.
    Any help or suggesstions in this regard would be very useful.
    Thanking you,
    khurram

    Hai,
    The requirement is like this
    There is an input file, the contents of the file are as follows, you can assume any name for the file.
    #Character mappings for Japanese Shift-JIS character set
    #ASCII character Mapped Shift-JIS character
    m 227,128,133 #Half width katakana letter small m
    n 227,128,134 #Half width katakana letter small n
    o 227,129,129
    p 227,129,130
    q 227,129,131
    r 227,129,132
    s 227,129,133
    t 227,129,134
    u 227,129,135
    v 227,129,136
    w 227,129,137
    x 227,129,138
    y 227,129,139
    z 227,129,142
    The contents of the above file are to be read as input.
    On encountering any character between m to z, i have to do a replacement with a hexadecimal code point value for the multibyte representation in the second column in the input file.
    I have the code to get the unicode codepoint value from the multibyte representation, but not from a file.
    So if you could please tell me how to get the characters in the second column, it would be very useful for me.
    The character # is used to represent the beginning of a comment in the input file.
    And comment lines are to be ignored while reading the file.
    Say i have a string str="message";
    then i should replace the m with the unicode code point value.
    Thanking you,
    khurram

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

  • Accessing RUN through java programming

    Sir,
    i need to develop a java application t access "run" in start menu.How can i access the run menu through java programming.?I want to run the program in the run command when we input command through the java program..please help me..if you have the code palese send it tio me please..........

    But I cant access the drives for eg: I wrote c:\programfiles as input but i got an exception like this
    error=3
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at ex.main(ex.java:10)
    how can correct this error...

  • Re:How to input database to java program

    Hi...anyone can briefly teach me how to input my Microsoft access(database) folder into my Java program?
    Or anyone have the java code to input data to the program?If i input do i need to declare a table first in it?
    Help Appreciated.Thanks...

    so far i only understand to hardcode...Can any one teach or give the source to input my text file and system output the data in a drop down list.
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ProductTable extends JFrame {
         String[] colNames={"Product ID","Product Name","Product Information","Product Price $"};
         Object [][] friendList = {{"1","Brown Bear, Brown Bear,What Do You See","Bill Martin Jr.","7.95"},
    {"2","Moo Baa La La La","Sandra Boynton","5.99"},
    {"3","Going-To-Bed","Sandra Boynton","5.99"},
    {"4","Animal Kisses","Barney Saltzberg","7.95"},
    {"5","Polar Bear, Polar Bear, What Do You Hear?","Bill Martin Jr.","7.95"},
    {"6","Tigers At Twillight","Mary Pope Osbourne","3.99"},
    {"7","But Not The Hippopotamus","Sandra Boynton","5.99"},
    {"8","Best Word Book Ever!","Richard Scarry","11.19"},
    {"9","Big Red Barn Board Book","Margaret Wise Brown","7.99"},
    {"10","Pajama Time","Sandra Boynton","6.95"},
    {"11","Time For Bed","Jane Dyer","6.95"},
    {"12","Make Way For Ducklings","Robert McCloskey","12.59"},
    {"13","Bear Snores On!","Karma Wilson","11.19"},
    {"14","Giraffes Can't Dance","Giles Andreae","11.2"},
    {"15","From Head to Toe Board Book","Eric Carle","15.37"},
    {"16","Blue Hat, Green Hat","Sandra Boynton","3.25"},
    {"17","Tails","Matthew Van Fleet","11.17"},
    {"18","Richard Scarry's Day at the Airport","Richard Scarry","3.25"},
    {"19","Richard Scarry's Best Storybook Ever!","Richard Scarry","11.19"},
    {"20","Stellaluna","Janell Cannon","11.2"},
    {"21","Salamandastron (Redwall, Book 5)","Brian Jacques","6.99"},
    {"22","What Color Is Your Underwear?","Sam Lloyd","9.99"},
    {"23","The Grouchy Ladybug","Eric Carle","7.99"},
    {"24","Mr. Popper's Penguins","Richard And Florence Atwater","5.99"},
    {"25","So Big!","Dan Yaccarino","7.99"},
    {"26","On Noah's Ark","Jan Brett","10.95"},
    {"27","Hey! Wake Up!","Sandra Boynton","6.95"},
    {"28","Can You Cuddle Like a Koala?","John Buttler","5.99"},
    {"30","Somebunny Loves Me: A Fuzzy Board Book","Joan Holub","4.99"}};
         JTable table=new JTable(friendList,colNames);
         JScrollPane scrollPane=new JScrollPane(table);
         public ProductTable(){
              Container contentPane=getContentPane();
              contentPane.add(scrollPane);
              setSize(500,200);
              setVisible(true);
         public static void main( String args[] )
              ProductTable app = new ProductTable();
              app.addWindowListener(
         new WindowAdapter() {
         public void windowClosing( WindowEvent e )
         System.exit( 0 );

  • Where does this java program read a text file and how does it output the re

    someone sent this to me. its a generic translator where it reads a hashmap text file which has the replacement vocabulary etc... and then reads another text file that has what you want translated and then outputs translation. what i don't understand is where i need to plugin the name of the text files and what is the very first line of code?
    [code
    package forums;
    //references:
    //http://forums.techguy.org/development/570048-need-write-java-program-convert.html
    //http://www.wellho.net/resources/ex.php4?item=j714/Hmap.java
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class Translate {
    public static void main(String [] args) throws IOException {
    if (args.length != 2) {
    System.err.println("usage: Translate wordmapfile textfile");
    System.exit(1);
    try {
    HashMap words = ReadHashMapFromFile(args[0]);
    System.out.println(ProcessFile(words, args[1]));
    } catch (Exception e) {
    e.printStackTrace();
    // static helper methods
    * Reads a file into a HashMap. The file should contain lines of the format
    * "key\tvalue\n"
    * @returns a hashmap of the given file
    @SuppressWarnings("unchecked")
    private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    HashMap map = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    String line;
    map = new HashMap();
    while ((line = in.readLine()) != null) {
    String[] fields = line.split("\\t", 2);
    if (fields.length != 2) continue; //just ignore "invalid" lines
    map.put(fields[0], fields[1]);
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return(map); //returning a reference to local variable is safe in java (unlike C/C++)
    * Process the given file
    * @returns String contains the whole file.
    private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    StringBuffer out = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    out = new StringBuffer();
    String line = null;
    while( (line=in.readLine()) != null ) {
    out.append(SearchAndReplaceWordsInText(words, line)+"\n");
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return out.toString();
    * Replaces all occurrences in text of each key in words with it's value.
    * @returns String
    private static String SearchAndReplaceWordsInText(Map words, String text) {
    Iterator it = words.keySet().iterator();
    while( it.hasNext() ) {
    String key = (String)it.next();
    text = text.replaceAll("\\b"+key+"\\b", (String)words.get(key));
    return text;
    * @returns: s with the first letter capitalized
    String capitalize(String s)
    return s.substring(0,0).toUpperCase() + s.substring(1);
    }

    without what arguments?Without any arguments. If there are no arguments, there are no arguments of any kind. If you have a zoo with no animals in it, it's not meaningful to ask whether the animals which are not there are zebras or elephants.
    does it prompt me to give it a text file name?Apparently.
    when i run it this is all i get:
    usage: Translate wordmapfile textfile
    Press any key to continue...Right. And "wordmapfile" is almost certainly supposed to be a file that holds the word map, and "textfile" is almost certainly the file of text that it's going to translate.

  • How to call JAVA program having input & output parameter

    Hi Experts,
    Require ur help in calling a java program in ODI which has input parameter & I need to also get the output of the java program.
    I have a java program which I execute through command prompt with input parameters required for the program.
    Also I need to get the output of the same java program & need to pass it as input to another Java program.
    kindly help...how to implement the java program in ODI as I have not worked on Java.

    Hi experts,
    kindly help...

  • Where to place    text file in  Jdeveloper9irc  to read from Java program

    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

    The test.txt file should be in the 'Run Directory" of your Project. Select Project.jpr and invoke Project settings dialog.
    Click on the Runner. You will see the "Run Directory" edit field.
    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

  • Can we give *.* as an input parameter to java program.

    i have a simple java program. In the program I’m giving the input parameter as *.*
    But in the main method, I’m getting the argument value as a different one. The name of one of the file in the current directory. Any thing that starts with * like *.txt* is giving the file name in the directory.
    How to parse the *.* through input parameter.
    public class test
         public static void main(String args[]){
              System.out.println("arg[0]-->"+args[0]);
    }

    This is a shell thing, not a Java thing -- your command line shell is expanding things like dot or star. You need to quote it to pass it to your program, unexpanded. The quoting syntax depends on your shell, but try single or double quotes:
    java UrPrgm '.' '*'
    //or
    java UrPrgm "." "*"

  • Sensor output as input to java program

    hi , pls tell me how to use output from infrared senors as input to java program..................???????
    mail me the code at [email protected]

    Hi,
    Check the following syntax:
    SUBMIT <rep> TO SAP-SPOOL
    [<params>|SPOOL PARAMETERS <pripar>]
    [ARCHIVE PARAMETERS <arcpar>]
    [WITHOUT SPOOL DYNPRO].
    Ex:
    The following executable program is connected to the logical database F1S:
    REPORT SAPMZTS1.
    TABLES SPFLI.
    GET SPFLI.
    NEW-LINE.
    WRITE: SPFLI-MANDT, SPFLI-CARRID, SPFLI-CONNID,
    SPFLI-CITYFROM, SPFLI-AIRPFROM, SPFLI-CITYTO,
    SPFLI-AIRPTO, SPFLI-FLTIME, SPFLI-DEPTIME, SPFLI-ARRTIME,
    SPFLI-DISTANCE, SPFLI-DISTID, SPFLI-FLTYPE.
    The following program calls SAPMZTS1 and sends the output to the spool system:
    REPORT SAPMZTST NO STANDARD PAGE HEADING.
    DATA: VAL,
    PRIPAR LIKE PRI_PARAMS,
    ARCPAR LIKE ARC_PARAMS.
    CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
    LAYOUT = 'X_65_132'
    LINE_COUNT = 65
    LINE_SIZE = 132
    IMPORTING
    OUT_PARAMETERS = PRIPAR
    OUT_ARCHIVE_PARAMETERS = ARCPAR
    VALID = VAL
    EXCEPTIONS
    ARCHIVE_INFO_NOT_FOUND = 1
    INVALID_PRINT_PARAMS = 2
    INVALID_ARCHIVE_PARAMS = 3
    OTHERS = 4.
    IF VAL <> SPACE AND SY-SUBRC = 0.
    SUBMIT SAPMZTS1 TO SAP-SPOOL
    SPOOL PARAMETERS PRIPAR
    ARCHIVE PARAMETERS ARCPAR
    WITHOUT SPOOL DYNPRO.
    ENDIF.
    Regards,
    Bhaskar
    Edited by: Bhaskar Chikine on Sep 9, 2008 4:33 PM

  • Can java program simulate keyboard input?

    is it possible to create a java program or applet that simulates an end-user's keyboard input into another java applet? is it also possible to feed the output of that target applet to a file based on the different input combinations?
    and How?
    Thanks.

    Take a look at the API-docs for the class java.awt.Robot . This generates system-level input-events. Might not work in an applet, I do not know whether an applet has the right to do this.
    The second question is actually the more difficult one, since normal applets can not do file access.

  • Java programs don't accept input from German Microsoft keyboard on Mac OS X

    Hi everyone,
    I use Microsoft's Natural Ergonomic Keyboard 4000 with a German layout and the current IntelliType Pro driver on a Mac (OS X 10.5).
    When activating the NEK 4000-specific German keyboard layout supplied with IntelliType Pro for Mac, Java programs cannot recognize keyboard inputs anymore. They can again as soon as I switch back to the standard German keyboard layout provided by Apple with OS X 10.5. However, this layout does not match the characters printed on the NEK 4000.
    This phenomon is limited to Java programs running on OS X with the IntelliType Pro's specific German keyboard layout activated. It does not occur with native OS X programs. Therefore, the problem could result from Microsoft's IntelliType Pro driver for OS X, Sun's Java Virtual Machine (in OS X), or Apple Mac OS X.
    Could a Sun employee please take a look at this issue?
    I am more than willing to provide the respective log files if this was needed.

    arne2 wrote:
    Sun's Java Virtual Machine (in OS X), Apple, not Sun, is the source of the VM on that OS.
    Apple probably gets it from Sun but still Apple is responsible for it.

  • Use ProcessBuilder to execute a java program with a file piped as input

    Hi,
    I am trying to execute a java program passing in input file as argument. I have to do this by forking a process and am using Processbuilder.
    I have a main function which calls the executeCliTopologyDesigner method. I get a Java I/O exception
    Caught IOException: Cannot run program "$JAVA_HOME/bin/java oracle.apps.fnd.provisioning.cli.TopologyDesigner ": java.io.IOException: error=2, No such file or directory
    Can you please let me know if I am missing something?
    Thanks,
    pkrish
    Code Snippet:
    private synchronized void executeCliToplogyDesigner(String cliCommand, File tmp)
    throws IOException, InterruptedException
    {    File temp= writeDataInTemp(compDefName);
    cliCommand = "$JAVA_HOME/bin/java oracle.apps.fnd.provisioning.cli.TopologyDesigner ";
    ProcessBuilder pb = new ProcessBuilder(cliCommand,"<",temp.getCanonicalPath());
    executeProcess(pb);
    Edited by: pkrish on Mar 2, 2009 3:56 PM
    Edited by: pkrish on Mar 2, 2009 3:57 PM
    Edited by: pkrish on Mar 2, 2009 3:58 PM
    Edited by: pkrish on Mar 2, 2009 3:59 PM

    Hi,
    I printed out the system environment variables PATH and CLASSPATH and it is as below:
    Classpath :/ade/prprasa_prov_latest/fmwtest/tools/orajtst/home/lib/orajtst.jar:/ade/prprasa_prov_latest/jdev/src/abbot/dist/EXTENSIONS
    Path :/ade/prprasa_prov_latest/fxtn/util/tools/ant/bin:/ade/prprasa_prov_latest/fmwtest/tools/orajtst/home/bin:/ade/prprasa_prov_latest/oracle/jdeveloper/jdev/bin:/ade/prprasa_prov_latest/javahome/jdk/bin:/usr/kerberos/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/ade/bin:/OracleProd/oracle10g/bin:/OracleProd/oracle10g/bin:/OracleProd/oracle10g/bin
    The Path does contain java.
    I changed my command as I need a different classpath.
    cliCommand = "/ade/prprasa_prov_latest/javahome/jdk/bin/java -classpath .:/ade/prprasa_prov_latest/oracle/provisioning/tools/lib/*:/ade/prprasa_prov_latest/oracle/provisioning/configframework/lib/*:/ade/prprasa_prov_latest/oracle/provisioning/framework/lib/*"
    Caught IOException: Cannot run program "/ade/prprasa_prov_latest/javahome/jdk/bin/java -classpath .:/ade/prprasa_prov_latest/oracle/provisioning/tools/lib/*:/ade/prprasa_prov_latest/oracle/provisioning/configframework/lib/*:/ade/prprasa_prov_latest/oracle/provisioning/framework/lib/*": java.io.IOException: error=2, No such file or directory
    Any ideas? Please let me know where do I post it if not here.

Maybe you are looking for

  • How do I access a library already on an external drive, from a new computer?

    I moved my library from an old hard drive onto a larger external drive, following the online instructions and then continued to use the old machine to access the library. I now want to swap computers completely (the library can stay where it is) but

  • Preloading time of flex mobile project seems long

    I have tried a few apps on iPad (e.g. Muni Tracker, Conqu) and the preloading time seems too long (6-10s). Actionscript-only mobile applications are much faster. I am curious to know what is happening during the preloading time, and what can we do to

  • Capturing and Timecode Help

    Hi, We're capturing DV tapes from a deck using a firewire cable to our Macbook and a USB cable to our external drive for the scratch disk. We're having trouble capturing - trying to capture each entire tape - but after short varied times with each ta

  • Can you apply fx to individual clips after a multicamera edit? CS6

    I have footage from a 5 camera shoot of a concert.  What I want to do is perform a multicamera edit to choose what angles I want to use.  After the edit, I would need to go back and apply warp stabilizer to any sections that need it.  One of the came

  • Photoshop crashing before I can do anything CS6

    I recently moved from CS3 to CS6 and now whenever I open a document and select the marquee tool or any other tool photoshop crashes straight away saying Adobe Photoshop CS6 has stopped working. This is Happening in both the 32 bit & 64 bit versions o