Java with Text file

Hi
I'm new in Java , just start 2 week agao, I want to read data for text file ...
Argentina | Armenia | Australia | Austria | Azerbaijan |
Canada | Cape Verde | Central African Republic | Chad | Chile | China |
I will use " | " to separate a string and to parse this string to array.
I have seen some the sample use : StringTokenizer but I didn't get about it
can you give me more information or short code

Sample code here: http://www.ccs.neu.edu/course/com3118/util2.html
You could also use String.split()

Similar Messages

  • Java loading text file and doing stuff help

    Hello,
    Can anyone help me with this, I just don't know where to start..
    I need to create a java program which will load up a text file. The text file must be no bigger than 1000 characters (so somewhere there needs to be an exception I am guessing)
    Once loaded, it needs to run some methods on the text file which each return a single statistical count, the methods need to count things like number of white space, number of vowels, frequency of each vowel (this would not need to return a single count but maybe update some sort of array?) , number of printable characters and number of consonants.
    Any help would be very good.
    Dean

    Thanks for the help so far
    But first things first, I should start at the
    beginning.
    I am thinking maybe start with something like from
    the Sun tutorial for 'CopyCharacters.java'.
    So we have the first part of the program that loads
    up the txt file....
    (I really would like to have GUI for this, but I
    can worry about that once the actual program is
    working
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    public class CopyCharacters {
    public static void main(String[] args) throws
    IOException {
    FileReader inputStream = null;
    FileWriter outputStream = null;
    try {
    inputStream = new
    FileReader("input_characters.txt");
    Right, now its time to actually read what is in the
    file and use some of the statements you have
    suggested, can anyone help me get started with this?
    Dean
    public class DeanHomeworkAssignment {
    public static void main(String args[]) {
    //Put your code here
    }There ya go, that should get you started.
    Start by writing the code to open the file.
    This isn't that difficult.

  • Domain Value Mapping with Text file

    Hai,
    I have done the Domain value mapping with the xml file to xml file and it is working fine.
    But in the case of Text file to Text file it is not working i.e. If the citiname is the
    first field it is domain value mapping and working fine.
    INPUT:
    Erode, Mahes, 22
    Coimbatore, Veera, 22
    OUTPUT:
    ED, Mahes, 22
    CBE, Veera, 22
    But if I change the Citiname to the second column it is not working the problem is
    it is not working for subsequent columns.
    INPUT:
    Mahes, Erode, 22
    Veera, Coimbatore, 22
    OUTPUT:
    Mahes,, 22
    Veera,, 22
    The input Text files are delimited by "comma" and optionally enclosed by "space".
    Does anyone have attained the DVM in the Text file successfully.
    Please help me.

    Thank you for the reply Abhi
    Text to Text means instead of giving the input file as XML file i am giving the input as a simple .txt file and I also want the output in the .txt format.
    For the text file only it is not working fine in the xml file to xml file it is working fine.
    For your another query I am not providing the correct parameters for "lookup-dvm"
    I am giving the xsl file
    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
    <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
    <mapSources>
    <source type="WSDL">
    <schema location="TextInput1.wsdl"/>
    <rootElement name="Root-Element" namespace="http://TargetNamespace.com/TextInput1"/>
    </source>
    </mapSources>
    <mapTargets>
    <target type="WSDL">
    <schema location="TextOutput1.wsdl"/>
    <rootElement name="Root-Element" namespace="http://TargetNamespace.com/TextInput1"/>
    </target>
    </mapTargets>
    <!-- GENERATED BY ORACLE XSL MAPPER 10.1.3.3.0(build 070615.0525) AT [TUE JUL 15 15:31:55 IST 2008]. -->
    ?>
    <xsl:stylesheet version="1.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
    xmlns:pc="http://xmlns.oracle.com/pcbpel/"
    xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions"
    xmlns:ns0="http://www.w3.org/2001/XMLSchema"
    xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:imp1="http://TargetNamespace.com/TextInput1"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/file/TextInput1/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:hdr="http://xmlns.oracle.com/pcbpel/adapter/file/"
    xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/file/TextOutput1/"
    exclude-result-prefixes="xsl plt pc ns0 jca imp1 tns hdr ns1 bpws ehdr hwf xp20 xref ora ids orcl">
    <xsl:template match="/">
    <imp1:Root-Element>
    <xsl:for-each select="/imp1:Root-Element/imp1:Leaf-Element">
    <imp1:Leaf-Element>
    <imp1:C1>
    <xsl:value-of select="imp1:C1"/>
    </imp1:C1>
    <imp1:C2>
    <xsl:value-of select='orcl:lookup-dvm("Citinames","Long",imp1:C2,"Short","")'/>
    </imp1:C2>
    <imp1:C3>
    <xsl:value-of select="imp1:C3"/>
    </imp1:C3>
    </imp1:Leaf-Element>
    </xsl:for-each>
    </imp1:Root-Element>
    </xsl:template>
    </xsl:stylesheet>
    Here I am checking the DVM function for the Second column and it is not working and I have given their Inputs and Outputs in my first message .
    I have another question as you told both import and export of the DVM is always in the XML format only so I have a doubt whether the lookup-dvm will be working for xml files only and not for text files.
    But in my case in text file it is working for the first column but not in the subsequent columns.
    Thanks.

  • Prepare List with text file fields

    Hi,
    This is rama krishna. I need to convert text file fields to a List.
    My requirement is to read a text file and prepare one list depending up on the fields.
    For example I want to read the following foollowing text fields into list(it may be list or linked list).
    <b>
    Invoice Number voice Date Voucher ID Gross Amountount Available Paid Amount
    51169 Nov/17/2005 00538767 7,043.23 0.00 7,043.23
    51275 Dec/14/2005 00542544 929.87 0.00 929.87
    601001 Jan/08/2006 00542545 1,837.14 0.00 1,837.14
    Vendor Number Check No Date Pay Amount Total Discounts tal Paid Amount
    21C029 218534 Jan/19/2006 $9,810.24*** $0.00 $9,810.24</b>
    I want Vendor number as on list to that list I want add
    Invoice nos lists.
    Thanks & Regards
    Rama Krishna

    Hi, Rama!
    Unfortunatly it' s beyond the scope of this forum to give that detailed advice on basic java se techniques like opening a file input stream and working with collections.
    Please refer to the suns standard documentation on file i/o and collections for detailed information on that.
    If you' ve any additional questions on more SAP specific problems, don' t hesitate to ask!
    Regards,
    Thomas

  • Java newbie & text files

    I want to create a simple program that will read a text file and put it in a variable to use later in the program. I can't figure out how to assign characters from the text file to a variable. Please bear with me, this is my latest attempt:
    import java.io.*;
    public class FileReader1 {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("nfo.txt");
    FileReader in = new FileReader(inputFile);
    String intext;
    int c;
    while ((c = in.read()) != -1)
    intext = (String)in;
    in.close();
    System.out.println(intext);
    }

    I used the BufferedReader method on the FileReader method to get a string instead of characters, thus I could easily assign the value to a string variable. Below is my solution:
    import java.io.*;
    public class FileReader1 {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("nfo.txt");
    FileReader in = new FileReader(inputFile);
              BufferedReader br = new BufferedReader(in);
              String s;
              String intext="";
    while ((s = br.readLine()) != null)
              intext = s;
    System.out.println(intext);
    in.close();
    }

  • How to create a mapping with text file as my target

    I need to create a mapping with source as a table and target as a text file.
    I am using OWB 10g R2. with database Oracle10g.
    Any one can help me to create a mapping with a text file as target.

    Hi,
    just create a File-Location and File-definition and use this file-operator as target object inside your mapping.
    Regards jwehner

  • Email with Text File Attachement as Source

    Hi All,
           One of my interfaces needs to listen to incoming mails with an text file attachements.I wish to know how we can convert the text file contents into XML to further process it on the reciever side.

    Hi,
    To perform content conversion of a flat file, check these blogs,
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    Also, to understand file content conversion better, you can check this link on SAP Help,
    http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
    Regards,
    Bhavesh

  • Michel: sync gtasks with text files

    I wrote Michel, a gtaks-to-text-file synchronizer. Michel is your friendly mate that helps you managing your todo list. It can push/pull flat text files to google tasks.
    Right now, it features two commands:
    michel pull
    prints the default todo list on the standard output
    michel push <TODO.txt>
    replaces the default todo list with the content of TODO.txt
    Of course you need a gmail account to make it work. It uses oauth, so when you start it the first time, it will give you an url to visit and you'll have to give access to the app, then it will save a token and won't ask next time. If you want to delete the token, it is stored in $XDG_DATA_HOME/michel/oauth.dat.
    The code is on github. As usual comments and patches are welcome...
    Last edited by duquesnc (2011-09-23 21:28:56)

    Oh, I have to add that currently, the package won't build correctly. That is not due to the python2-google-api-python-client package which does not set the rights correctly. A quick and dirty fix is to
    # chmod +r /usr/lib/python2.7/site-packages/google_api_python_client-1.0beta4-py2.7.egg-info/top_level.txt
    I notified the owner of python2-google-api-python-client of the correct change to do.
    Last edited by duquesnc (2011-09-23 21:26:35)

  • Receiver mail with text file attached without line feeds

    Hi, friends
    I have a text file  to mail scenario, where file must be attached to receiver mail.
    Receiver CC mail is protocol XIPAYLOAD and use mail package and keep attachment.
    In tab module, i have:
    Module name --> SAP XI Sample/ConvertCRLFfromToLF
    Module configuration --> mode LFtoCRLF
    The plain text file is attached to mail but there are no line feeds after the plain text lines.
    Thanks, in advance

    Stefan,
    This is not a Java mapping, it's an ABAP mapping.
    I've tryed also to insert this characters, but without success.
    In my abap class i have:
      data: l_newline type c value cl_abap_char_utilities=>newline.
      data: l_linefeed type c value cl_abap_char_utilities=>CR_LF.
      clear wa_string.
      incode = idocument->get_elements_by_tag_name( 'linea' ).
      length = incode->GET_LENGTH( ).
      do length times.
        outcode = incode->get_item( index = d_lines ).
        wa_linea = outcode->get_value( ).
        if wa_string is initial.
          wa_string = wa_linea.
        else.
          concatenate wa_string l_newline  l_linefeed crlf wa_linea into wa_string.
        endif.
        add 1 to d_lines.
      enddo.
      l_element_dummy  = l_document->create_simple_element(
                    name = 'Content'
                    VALUE = wa_string
                    parent = l_element_root  ).
    so...it's similar to your suggestion..
    Any other input, please?
    Regards,
    Carme.

  • Compare with text file

    Is it possible to do a line by line compare with the data in a text file and print the required data?
    BufferedReader readCode = new BufferedReader(new FileReader("code.txt"));
    String code = readCode.readLine();
    while(more) {
    System.out.print("Code:");
    String productCode = in.readLine();
    while (code != null){
         code = readCode.readLine();
         if (!(productCode.equals(code) || productCode.equals(code) || productCode.equals(code) ||productCode.equals(code) || productCode.equals(code) || productCode.equals(code) || productCode.equals(code) || productCode.equals(code))){
         // Goes back to the next loop interaction. Skiping the rest of the loop below
         System.out.println("Invalid product code. Check the product code again");     
         continue;
    productTemp[j] = productCode;
    do{
         /*Keep asking for a quantity until some valid value is entered
         System.out.print("Quantity[0-100]:");
         productQuantity = Integer.parseInt(in.readLine());
    }while(productQuantity > 100 || productQuantity < 0);
    quantity[k]=productQuantity;          
    totalQuantity = quantity[k] + totalQuantity;
    j++;
    k++;
    noOfItems++;          
    }     i cant seem to compare the user input code with the code in my textfile.i am stuck here...can somebody enlighten me?

    nvm...thanks for ur help anyway..i try others
    ways..save ur remarks for other pplThis is a public unmoderated forum. If you don't want remarks, don't post.
    Besides, if you're not willing to describe your problem in better detail, what kind of "help" do you expect? It's not like you've entered a forum full of psychics. Your problem is unclear. You've been given suggestions. If you have a more specific question, feel free to ask. Otherwise, feel free to continue floundering about.
    Good luck.

  • Reloading a 3500XL with Text File

    How do I clear the config and reload the switch with a text file? I have the file ready to go but can't figure out how to get it to take. Any help would be appreciated. Thanks.

    Erase startup
    reload
    N Don't do the config!
    enable
    copy and paste the text file
    ATTENTION do NOT paste from a Wordprocessor like MS-WORd, they add all the ugly control codes(especially fun at the password!)

  • Help required with text file handling in GPIB

    Hi attached is my vi for GPIB communication with Aginelt Network Analyzer in Labview 8.
    I'm saving the data of network analyser into text file(appending all the data). I wish to make some changes into it. As can be seen there is a input which asks for number of points/segments. Supposed I give that input as 201 points(it can be 401,801,1601,51,etc.) than after every 201 points data should get appended into a new coloumn and not into 202 row. Seperate coloumn should start for the whole set of 201 points, where as currently what is happening is all the data is getting appended one below the other.
    Can anyone help around,
    Regards
    Attachments:
    finaltemp.vi ‏52 KB

    Here...
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
    Attachments:
    finaltemp(80).vi ‏52 KB

  • Servlet combination with text file ...

    hai dude , i wanna ask some a terrible question
    may be you can help me with this ...
    i made servlet admin for loggin into system , but in this case
    i used text file not database (sql,or else) .
    for example i have admin.txt and contain :
    admin myadmin
    admin refers to username and myadmin refers to password
    can you guys show me a little program servlet that i can learn
    and study about login with servlet !!!!!!

    Should be something like this:
    public class theServlet extends HttpServlet
    private Hashtable namePassword = new Hashtable();
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    try
         BufferedReader br = new BufferedReader(new FileReader("admin.txt"))
         String line = "";
         while ((line=br.readLine())!=null)
              // getting data from the lines
              // every line have to be the form: username password
              StringTokenizer stk = new StringTokenizer(line);
              namePass.put(line.nextToken(),line.nextToken());
         br.close();
    catch (Exception e)
         e.printStackTrace();
    public void doGet( HttpServletRequest req, HttpServletResponse resp )
    throws ServletException, IOException
    resp.setContentType("text/plain");
    PrintWriter out = resp.getWriter();
         // the calling html-page have to have a form with the textfields username and password
         String username = req.getParameter("username");
         String password = req.getParameter("password");
         if (((String)namePassword.get(username)).equals(password))
              out.println("Login OKAY!");
         else
              out.println("Login failed!");
    } // End doGet

  • SQL insert statement in java with Excel file

    Dear all,
    I wrote a program is as the follow:
    import java.io.*;
    import java.sql.*;
    public class handleExcel
         Connection con = null;
         Statement stmnt = null;
         public handleExcel()
              String excel = "C:\\EGS\\app_files\\info_update_form_exported_data.xls";
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   String str="jdbc:odbc:DRIVER=Microsoft Excel Driver (*.xls);DBQ=" + excel + ";";
         String sql = "insert into [Sheet1$] (Name, Age, Test1, Test2, Test3) values ('mary','16','aa','bb','vv')";
                   con = DriverManager.getConnection(str, "", "");
                   stmnt = con.createStatement();
                   stmnt.executeUpdate(sql);
              catch(Exception e)
                   System.out.println("con is error!!");
                   e.printStackTrace();
         public static void main(String[] args)
              handleExcel TestHpc = new handleExcel();
    But when I run it, the error is as the follow:
    java.sql.SQLException: [Microsoft][ODBC Excel Driver]
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
         at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
         at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
         at hk.gov.edb.util.handleExcel.<init>(handleExcel.java:31)
         at hk.gov.edb.util.handleExcel.main(handleExcel.java:97)
    Please help me to solve this problem. Thank you so much for your help!
    Regards,
    kzyo

    Hi
    You can use the[b] jakarta POI api in order to read/write Excel file from java. Pure Java, no drivers nedeed.
    I tested and ok.
    Hope this helps

  • Problem with Text file attachment

    Hello All,
    I am sending data from my program via mail in an attachment of text format in 4.6C. But the format of the data in the attachment is not correct. There is no line break in the data.
    I've tried putting the line break manually by using hexadecimal code '09' as the line break. But it is not working.
    Kindly suggest.
    Thanks

    Hello Brad,
    I marked the problem as solved previously because the issue of all the lines coming together was solved.
    So, I marked the question as solved.
    Now, I have a different problem and rather than creating a new thread I opened this one only.
    Thank you

Maybe you are looking for

  • Java.rmi.ConnectException: Connection refused to host: 10.41.8.140; nested exception is:

    Agile:9.2.2.1 linux-x86_64

  • Add my own music videos to iTunes

    When i add a music video or an episode of TV show to iTunes, it will always file it under the "Movies" tab. The music videos i buy on iTunes will always be filed under "Music Videos"...i have tried playing around to tag my own music videos as "music

  • Resolution is horrible on new ATV3

    So I picked up the new ATV3 on Friday and have it all hooked up to my Denon AVR2311 receiver using HDMI.  Everything seems to be working but all of the content looks horrible when I view it on my 55" TV.  I tried iTunes content and previews of 1080P

  • Is this a new problem for the zen mic

    I havent found anything about this on the forum but I have to agree that I didnt search a lot , but since a couple of days, I got a new problem on my micro, it started skipping part into some songs then would go back and then skip some parts, it's ve

  • Can't open the configuration window in Airport Utility

    The Airport Utility was able to recognized my AEBS, but failed to read the setting of my AEBS and therefore can't successfully opened the configuration window; just asked me to check if my computer was within range ??????? Logging into the config pan