File reader and comparing words

hi, im currently trying to create a project and i need a little help to get it started!
What i need to do is create an application which can read a text file. I also need to have a list of words already in the application, and if a word in the list is also in the text file, id like this to be printed in the terminal.
can anybody help me out with how to start this? ive been looking for relevant posts, and there seems to be alot of things on file reading and comparing words, but they r pretty difficult to follow and not really the same as what im looking for.
thanks for your help!
Torre

You can place a for loop within a for loop to to compare every word in the temp array with every word in the other array.
try {
String[] array = new String[] {"wow", "cool"};
BufferedReader in = new BufferedReader(new FileReader("text.txt"));
String str;
while ((str = in.readLine()) != null) {
String [] temp = null;
temp = str.split(" ");
for (int i = 0 ; i < temp.length ; i++) {
  for(int j = 0; j < array.length; j++) {
    if (array[j].equals(temp)) {
System.out.println(temp);
} catch (IOException e) {
} finally {
//Always close your resources in your finally block... good coding practice.
in.close();

Similar Messages

  • File read and write operations

    how do use file read and write operations?
    can anyone give simple program?

    http://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm
    http://www.cplusplus.com/doc/tutorial/files/
    check this
    and with mfc
    http://www.functionx.com/visualc/fileprocessing/serialization.htm
    https://msdn.microsoft.com/en-us/library/6337eske.aspx
    http://www.informit.com/library/content.aspx?b=Visual_C_PlusPlus&seqNum=90

  • IPhone4 how through the USB mobile phone file reading and writing?

    iPhone4 how through the USB mobile phone file reading and writing?

    No idea what you are asking.
    Please explain

  • File Reader and BuffredReader

    Hi All,
    Is it that one buffred reader object works with one file reader.???
    I am writing a code for reading the text files with fixed format,
    So i used one file reader and operated two buffered reader object with the same file reader,
    but its not working.
    Please help

    Is it that one buffred reader object works with one
    file reader.???what?
    I am writing a code for reading the text files with
    fixed format,
    So i used one file reader and operated two buffered
    reader object with the same file reader,
    but its not working.what do you mean by "not working"?
    post your code so that people know what you are trying to do.

  • Problem With File Reading And Sorting

    I'm having problems with a particular task. Here is what I have to do:
    Write a program which reads 100 integers from a file. Store these integers
    in an array in the order in whcih they are read. Print them to the screen.
    Sort the integers in place using bubble sort. Print the sorted array to the
    screen. Now implement the sieve of Eratosthenes to place all prime numbers
    in an ArrayList. Print that list to the screen.
    Here is the code I have so far:
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add();
            catch(Exception e)
    This is the file reading part I have done but it doesn't recognise the line numbers.add() . It brings up the error - 'Cannot resolve symbol - method add(). Thats the first problem I have, can anyone see any way to fix it and to achieve the task. Also can someone help with the structure of a bubble sort method and a sieve of Eratosthenes method as I have no clue whatsoever. Any help will be greatly appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Ok, I've done that but I'm having another problem. When I'm printing an output to the screen, it prints 100 lines of integers and not 1 line of 100 integers. Can you see the problem in the code that is doing this?
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add(temp);
                    System.out.println(numbers);
            catch(Exception e)
    }

  • File Read and Write using File Adapter in Bpel

    In Bpel Process i am using File Adapter ( Schema is Opaque) for read and write the file contents. i am able do successful deployment and read, write function in first time deployment, after that again i tired to run the application, its not going to write the content of file, its only writing the file with out data's or content in that file.
    Please help me...
    Saravanan

    Hi Eric
    In my domain.log file having the following details. In this file im unable to find out what the exact problem. Please look at this and help me.
    <2008-01-22 18:25:42,024> <INFO> <default.collaxa.cube.compiler> validating "C:\product\10.1.3.1\OracleAS_1\bpel\domains\default\tmp\.bpel_BPELProcess2_1.1_298e83988d77b6640c33dfeec11ed31b.tmp\BPELProcess2.bpel" ...
    <2008-01-22 18:25:49,850> <INFO> <default.collaxa.cube.engine.deployment> <CubeProcessFactory::generateProcessClass>
    Process "BPELProcess2" (revision "1.1") successfully compiled.
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Loading JCAActivationAgent for {portType=Read_ptt}
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Locating Adapter Framework instance: OraBPEL
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Done loading JCAActivationAgent for processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.engine.deployment> Process "BPELProcess2" (revision "1.1") successfully loaded.
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::uninit Shutting down the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.0/', activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - performing endpointDeactivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Endpoint De-activation called in adapter for endpoint : D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::init - Initializing the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::initiateInboundJcaEndpoint - Creating and initializing inbound JCA endpoint for:
    process='bpel://localhost/default/BPELProcess2~1.1/'
    domain='default'
    WSDL location='rd.wsdl'
    portType='Read_ptt'
    operation='Read'
    activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <File Adapter::Inbound> Endpoint Activation called in File Adapter for endpoint: D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - successfully completed endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,890> <WARN> <default.collaxa.cube.activation> <File Adapter::Inbound> PollWork::run exiting, Worker thread will die
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Managed Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> FileInteraction Created

  • File Read and Extract

    Hi,
    I have a script which runs and generates log files. Rather than manually read through these log files, I'd like to code a program which will take the file, read through it and extract the data I wish to extract.
    For example, it may read:
    bla bla bla
    bla bla bla
    23/03/05 - 151105 Files
    bla bla bla
    23/03/05 - Elapsed Time: 3m 50s
    bla bla bla
    24/03/05 - 51250981502 files
    bla bla
    24/03/05 - Elapsed Time: 59m 12s
    bla bla
    etc etc.
    So I want to ignore the "bla bla bla", pick out my keywords, such as file, time and print out the number next to it, preferably to a nice little html file or something :)
    I am able to read files and I think I can pick out keywords using string tokenizers, although this is more advanced than tokenizers I've used before. I used a buffer to split the file and read it line by line.
    I'm pretty stumped, although this seemed like a straight forward thing to do at the time....
    Any advice to get me going?
    Thanks!

    you could use a reg ex to match on xx/xx/xx and still read line by line.
    or you could use Integer.parseInt and always parse the first two characters of a line, if they parse they are integers, but maybe blah has integers in the first two positions as well.

  • Large File Reading and Processing

    Hi:
    Suppose I have a file much larger than my computer's memory e.g. say on a Windows XP system, the memory is 256 MB RAM and the file size is 1 GB on disk. Now if I want to create a File object and read from this file, is this possible to do? If yes, how about the performance?
    I understand that this is more of an Operating System question but nevertheless it affects the Java process.
    Thanks!
    Rahul.

    If you mean, you plan to read the whole file into memory, then:
    Theoretically possible, sure. The process would be much bigger (in terms of memory used) than the amount of memory available, which means that it would start swapping out to disk, and that would reduce performance, although to what extent depends on XP's virtual memory implementation, which I know nothing about.
    But if all you mean is that you want to create a File object and read bits of the file, it won't make any difference. File represents a name or description of a file, not the file itself (you can create File objects for files that don't exist). So it doesn't need to read the whole into memory just to create a File object. You can easily create a File object for the huge file, and then read it in line by line, throwing away old lines as you go, and you won't use up very much memory at all. (Unless, of course, there's some horrible weird artifact of XP that I'm not aware of.)

  • File Read and write in Flex

    hi,
    can any one tell me how to read and write a file using
    actionscript in flex2
    regards,
    Shah Mohamed

    Hi all,
    I have tried read and write file using AIR inturn in Flex 3
    .I can able to compile it with no errors. But while i try to run
    ,it throw an error .and the stack trace of the error is below.. Im
    in showstopper stage. kindly update me with your suggesstions .
    Expecting the reply..
    Thanks in advance
    VerifyError: Error #1014: Class flash.filesystem::FileStream
    could not
    be found.
    at [newclass]
    at
    global$init()[D:\dev\nexxus\metasoft\iGallery;com\metasoft\flex\util;MetasoftUtils.as:8]
    at
    com.metasoft.flex.server::MetasoftServer/getUserInfo()[D:\dev\nexxus\metasoft\iGallery;co m\metasoft\flex\server;MetasoftServer.as:146]
    at
    com.metasoft.flex.server::MetasoftServer/isValidUser()[D:\dev\nexxus\metasoft\iGallery;co m\metasoft\flex\server;MetasoftServer.as:17]
    at
    components::Login/components:Login::login()[D:\dev\nexxus\metasoft\iGallery;components;Lo gin.mxml:14]
    at
    components::Login/__loginButton_click()[D:\dev\nexxus\metasoft\iGallery;components;Login. mxml:102]
    at [mouseEvent]
    regards,
    Shah Mohamed.N

  • Multi files reading and plotting

    i got three text files to be read  and i wana plot them on a single chart ,how can i do that ?? bundling them??
    And is there any way to write three different values on a single file in three columns ??? i m doing it with matlab ? is there any direct way??

    Hello,
    See if the attached file it's enought.
    For writting the 3 different values in 3 columns, use the "write to spreadsheet file.vi"
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Read3files.PNG ‏9 KB

  • How do I protect File (read and copy only)

    I have created a photo file that I want my kids to be able to see and copy( make an imovie or slideshow with)but not write onto. This way as I update the file with more pictures I can copy the new items over easily without creating copies of pictures. The file size is currently 250GB and to re-write the entire folder each time takes 8 hours and it might only take minutes if it only has to write the new pics. My hope is to be able to drag the file onto their drive and then for the system to ask if I want to replace or ignore existing files and just write the new ones. I want to be the only one that has the capability to do this. Help

    If you control their Apple menu -> System Preferences -> Accounts to have parental controls, you can keep that file inside a read only folder that you create for them to access. That's true for nearly every version of Mac OS X.
    If you are able to boot into Mac OS 9 on any of your machines, you will have to setup those accounts to boot via Apple -> Control Panels -> Users and Groups to have read only folders.
    Secure your account with a password that no one can guess. Birthdays, names, foreign language words are not good passwords. A mixture of consonants, numbers, and symbols are best, and at a minimum 8 characters.

  • Regarding read and compare of internal table.

    HI,
    i want to read internal table based on key pernr.
    suppose if we load the dec month data we want the last record of that month.
    if we load march 2008 data we want todays record.
    for this there are two fields datefrom and dateto.
    how to compare thesse two fields in read statement.
    regards,
    swami.

    Hi,
    Check this code
    loop at itab.
    endloop.
    if month = december
    read table itab with key sy-tabix = sy-dbcnt.
    "above stmt will fetch the last record
    elseif month = march
    read table itab with key sy-tabix = 1.
    "above stmt will fetch the first record.
    endif.
    Reward if helpful.
    Regards.

  • How to modify a datafile using file read and file write

    I have a datalog file containing port and DMM setup information.  I want to read this file into an aray, update or modify it, and write it to a file.  I can read the file in, but I am at a loss on how to modify it since it is stored in an indicator.  Any suggestions?

    The simplest thing is to replace your indicator by a control, and to use a local variable to write your data into the control.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Csv file reading and voltage and current plotting with respect to time samples XY plotting

    Hallo,
             I've been struggling with reading  a comma separated value (csv) file from another instrument (attached). I need to plot this data for analysis. I have 5 column of data with numbers of rows, the first three row is the information of the measurement. I want to read 4th row as string and rest of the row as numbers. I want to plot 2nd column (i1)  with respect to TIMESTAMP; 4th column(u2) wrt TIMESTAMP. And finally plotting i1 (x-axis) vs.. u2 (y-axis) in labview. Could anyone help me.
    In excel its so easy to plot  but I don't know how its done in labview.
    Attachments:
    labview forum test.csv ‏30 KB
    excel plot.jpg ‏88 KB

    Start by opening the file.  Then use the Read Text File function.  You can right-click on it and configure it to read lines.  First make it read 3 lines (this is your extra header data).  Then make it read a single line.  That will give you your channel names.  Then read the rest of the file (disable the read by line and wire a -1 into the number of bytes to read).  Then use the Spreadsheet String to Array function to give you your data.
    I would recommend going through the LabVIEW tutorials if you are really new at this.
    LabVIEW Basics
    LabVIEW 101
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Text file reading and writing problem

    Hello ! i am working on an electronic diary project and i am using Netbeans for that... i have finished all the rest but i am stuck into the saving of the appointments which i have been making.. i am using text files to save the entries ...what i am doing currently is that i am creating a file of every date which a user selects in the combobox.but if i want to add more appointment on the same date , then it overwries the previous one. i need to write something which can store multiple appointments in the same file.
    the writing code is:
    try {
    String aa = jTextField1.getText();
    String ab = jTextField2.getText();
    String ac =(String)jComboBox2.getSelectedItem();
    String ad =(String)jComboBox3.getSelectedItem();
    String ae = jTextField5.getText();
    String af =(String)jComboBox1.getSelectedItem();
    String ag = jTextArea1.getText();
    String outputFileName = ab+ac+ad+".txt";
    FileWriter outputFileReader = new FileWriter(outputFileName);
    PrintWriter outputStream = new PrintWriter(outputFileReader);
    PrintWriter outputStream1 = new PrintWriter(outputFileReader);
    PrintWriter outputStream2 = new PrintWriter(outputFileReader);
    PrintWriter outputStream22 = new PrintWriter(outputFileReader);
    PrintWriter outputStream3 = new PrintWriter(outputFileReader);
    outputStream.write(aa);
    outputStream1.write(ae);
    outputStream2.write(af);
    outputStream3.write(ag);
    outputStream.close();
    } catch (IOException e) {
    System.out.println("IOException:");
    e.printStackTrace();
    when i read the code , it doesnot reads the one which i store the text in new line...
    thanks

    Hi Dear
    Actually apending in your file is False so that it is overwriting this. do one thing open append option then it will add your data. for this just user true as the parameter with file name as i write in the below line. bedefault overwriting is false. you have to make this true.
    BufferedWriter out = new BufferedWriter(new FileWriter("Out.csv",true));
    try this your problem will solve.

Maybe you are looking for

  • SAP NetWeaver 7.02 SP9 64 bit AS ABAP Trial Vers w Java(TM) 6 Upd 31 Oracle

    Hallo all, I'm going to install SAP NetWeaver 7.02 SP9 64 bit Application Server ABAP Trial Version It is said that    JRE 1.4.x or JRE 1.5.x (for installation only) is required and that    (JRE 1.6 is not supported) Actually on my Windows-7-PC I ins

  • Payment Run for Customers

    Hi All, In case of payment to the customer by executing/running F110, do we need to set up all customers as vendors in order for the F110 run to pick up the open items. There is a Customer Accounts field where you can enter the range of customer acco

  • Problems with 10.5.6 update

    I seem to have problems with the update. Today I had a kernel panic and in the past it would just shut down. This all happened after the update. Can I go back to 10.5.5 with Time Machine? If so how do I do it? Do I have to reinstall all my software a

  • Mobility settings problem

    Finally I managed to get my MacBook set-up and configured for network access and a user set-up as a mobility user. Everything works with one teasing problem: I can't change in "Users & Groups" the Mobile Account Settings for the user. Everything is g

  • Fresh Install of Mtn Lion on new SSD More Difficult Than I Thought

    Today I installed my brand new 512GB SSD from Crucial. Had wanted a fresh install of Mtn Lion, but that turned out to be difficult. As a result, I resorted to a restore of my most recent Time Machine backup, which completed just fine. Changing out th