Problem comparing one line of a file to a different line

Hey guys,
i have a list of emails with a bunch of duplicates and i want to have one of each address. The logic behid the program is it would read in the first email, see if its in the second email list. If the email isnt in the new list it would print it to the new list and go to the second email adress and repeat the prossess.
can you please help me fix this program so it would do this?
Thanks guys
//DuplicateRemover2.java
import java.util.*;
import java.io.*;
public class DuplicateRemover2
     public static void main (String[] args)
          FileOutputStream out;
          PrintStream p = null;
          String fileName = "newemails.txt", fileLine = "", email = "emails.txt";
          Scanner file = null;
          Scanner otherfile = null;
          Scanner s = new Scanner(System.in);
          String listname = " ", scanname = "";
          int count = 0;
          try
               file = new Scanner(new File(email));
               out = new FileOutputStream(fileName, true);
               p = new PrintStream( out );
               otherfile = new Scanner(new File(fileName));
          catch (Exception e)
               System.out.println ("Error writing to file");
               System.exit(-1);
          while (file.hasNext())
          scanname = file.nextLine();
               while (otherfile.hasNext())
               count = 0;
               listname = otherfile.nextLine();
               if (listname.equals(scanname))
               count++;
               if (count == 1)
               p.println (listname);
}

morshed_nsu wrote:
Take an Arraylist object. After reading every email address, check if it is in the arrayList or not. If not then put it into the arrayList and write it to the out file. If it is in the arrayList read the next address.The set (suggested in the previous post) already does this check for you. You can only add something to a set that does not already exist in the set, there is no need to perform this check yourself.

Similar Messages

  • File SIZES are Different ?

    Hi Experts,
    I have implemented ESR By pass Scenario.
    The problem is we are getting the file sizes are differently in Source folder and Target folder
    How can we resolve this issue
    Please Guide Me
    Thanks and Regards,
    Ravi Teja.

    Refer to question no. 2 under the below wiki and see if that configuration helps.
    Sender File Adapter Frequently Asked Questions - Process Integration - SCN Wiki

  • After saving a htaccess file, why the text is on one line

    hello all,
    I am a webmaster and some time I have to setup a htaccess file (.txt file)When I edit it with Textedith, I make a modification and I save it. Nothing works.
    When I open the same file with a PC, all the text is in one line. of course it will not work.
    Can some one tell me why the file is not saved in the format when I open it, so it saved in one line?

    TextEdit isn't the best choice for editing configuration files, since it doesn't use Unix line endings -
    I thought TextEdit did use Unix line endings (LF). The reason it is all one line on a PC is that PC's do not, and thus will only display new lines if line endings are Windows format (CR + LF).
    I don't think there should be any problem editing config files with TextEdit, but TextWranger is better, and it also easily handles file names that begin with a dot.

  • How to handle multiple threads to read one line from a file each time?

    Dear Sir or Madam,
    I'm new to multiple threads java programming. What I want to do is as following:
    1. I'm writing a program to read one line of text from a very large file, and then do some process on this one line of text, then read the next line of text from this file, then process on this line of text, ...... When reach the end of the file, close the file.
    This is a single thread scenario.
    2. To fullly untilized computer resource, I want to create multiple threads to process this large file.
    One thing is very important is that each line of text in the large file has to be read sequentially. This means that the first line of text in the large file is read first, then the second line, then the third line ......
    My question is that if I create multiple threads to process the same file, how can I make sure that different threads will read the line of text from the same file sequentially?
    I don't have enough experience on java multiple threads programming, so it will be very appreaciated if you can help me on this as soon as you are available.
    Thanks and regards,
    Steven Wu

    A better solutoin would be to have a single thread that reads each line an puts it into a queue, and then multiple threads reading from the queue to process these lines.
    This will only be effective if the amount of processing to be done on each line is very large compared to how long it takes to read the line, or if you have more than one CPU on your machine.

  • Write To Measurement File Only One Line Of Data

    Hello,
    I have an express VI setup to acquire a single channel of strain running in a simple while loop.  The output is wired directly to a Write To Measurement Express VI.  However, the resulting measurement file contains only one line of data.  
    I have tried changing the settings of the VI to no avail.  I feel that I must be missing something basic.  My while loop is setup to take one measurement on demand for each loop.  I am assuming the VI knows to write each loop as a new line of data?  
    Thanks for any help,

    Did you choose "append to file" in the Express VI configuration settings?
    You need to upload your VI for further help.  It's impossible to help someone debug a problem without the code to look at.

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • My problem is too complex for a simple one-line question. Is there an upload facility where I can describe the problem in some detail?

    My Problem with Word and Excel for Ms Office 2011
    I work on a MacBook Pro (Mavericks, v.10.9.1) as an editor of a scholarly journal.
    I regularly receive submissions as Ms Word, Excel and PowerPoint files, mostly created  on Windows computers.
    For the past 10 years I have been using Ms Office software for Mac without any problems to open and process these documents.
    I have since 2012 been using Ms Office 2011 for Mac without without any problems.
    About 10 days ago, I started getting  error messages when trying to open Ms Word and Excel  files, but I have no problems with opening and editing PowerPoint files.
    Failed Clean Reinstallation Attempts
    I completely removed all traces of  Ms Office from every nook and cranny of my Mac, following the procedure  “How to completely remove Office for Mac 2011”  from the MS support website at  http://support.microsoft.com/kb/2398768, and then made a clean reinstallation of Ms Office 2011, followed by two recommended updates.  The problem is back.
    The Error Messages
    When I click on an existing .DOC or .DOCX Word file I get the following error message:
    (1)
    "The Open XML file Normal-dotm cannot be opened because there are problems with the contents or the file might contain characters (for example, \ /)."
    Details
    No error detail available.
    It then lists the name of the document that I was unable to open.
    (2)
    If I click on the image of a Blank page in the Word Document Gallery the following error message is displayed:
    "Word cannot open the existing global template
    (Normal.dotm)."
    (3)
    If I then click on OK, a blank document 1 opens up. When I type information and try to save it I again I get the error message:
    This is not a valid file name. Try one or two of the following:
    *Check the path to make sure it was typed correctly.
    *Select a file from the list of files and folders.
    Workaround Solution by Editing Ms Word Documents Via Pages
    I can open the Word documents that Word cannot in My Mac’s Pages word processing program, and after editing, export them again in Ms Word format, but cannot open the in Ms Word for Mac to see if everything is alright. This is no way to work, using Ms Word.
    Any suggestions how I can solve the problem, sort of buying Ms Office 2013 for Mac?
    (By the way, I am writing this message in Mac’s Notes application).
    <Edited by Host>

    Rembrandt,
    Did the two updates to Office 2011 get you to 14.3.9? That's the latest Mac version of Office.
    I use Office 2013 and Mac Office 2011 on the same machine and have no problems opening any files shared between the two. You followed the instructions for uninstalling and updated your new installation correctly, I have to assume. It sounds as if there is a problem with your cuurent configuration but if it's not an update problem, or an installation problem, I can only direct you to the MS Office for Mac user community -> http://answers.microsoft.com/en-us/mac (sometimes you get lucky and get an actual MS employee answering your question).
    Good luck,
    Clinton

  • Utility to send text file over GPIB, one line at a time?

    We are developing instrumentation that receives data and commmands over GPIB as plain text, and returns them as well. I'd like to create GPIB "batch" files and send them over the bus, one line at a time, so I can debug the instruments' behavior. I'd also like to be able to read back responses, one line at a time.
    Is there such a utility? I've got our programmer working on something like this, but I'd hate to have him re-invent an existing wheel.
    Thanks!

    Apart from NI-SPY, I have not heard of such a utility. This may be simple to implement using proper termination. If the instrument is capable of sending line feeds or carriage return, you should be able to easily create a document. Also, using IBWRTF, you could write the ASCII file (containing the termination characters) to the bus. Depending on how you have your timeouts specified, this may be ideal.
    Alternately, if you read a static amount of data, you could IBRD chunks of data. the result may need editing for broken words at the end of a line but would achieve such a result.
    Ryan Mosley
    National Instruments, Applications Engineer
    http://www.ni.com/exchange

  • I have a few hundred duplicates in my iPhoto library, but the file sizes are different.  So one is 1.3mb and one is 567kb.  I want to delete the smaller ones, but short of comparing each duplicate, is there a way to do this?

    I have a few hundred duplicates in my iPhoto library, but the file sizes are different.  So one is 1.3mb and one is 567kb.  I want to delete the smaller ones, but short of comparing each duplicate, is there a way to do this?  I've been looking at Duplicate Annhilator but I don't think it can do it.
    Thanks!

    I just ran a test with iPhoto Library Manager, Duplicate Annihilator, iPhoto Duplicate Cleaner, Duplifinder and Photodedupo.  I imported a folder of 5 photos into a test library 3 times, allowing iPhoto to import duplicates.  I then ran the 5 photos thru resizer to reduce their jpeg compression but all other aspects of the file the same.
    None of the duplicate removal apps found set that was reduced in the file resizer. That's probably due to the fact that the file creation date was being used as a criteria and the resized photo would have a different file creation date even though the Image Capture date was the same.
    They all found the 3 regular duplicates and some of them would mark two and leave the 3rd unmarked.  iPhoto Duplicate Cleaner can sort the found duplicates by file size but if the file was edited to get the reduced file size it might not be found as it would have a different file creation/modification date. 
    iPhoto Library Manage was able to find all duplicates and mark them as such if the file names were the same the the filename option was selected.  Otherwise it also missed the modified, resized version.  It allowed one to select the one photo to save before going to work on the library.
    So if a photo has been reduced in image quality or pixel size it will not be considered a duplicate.
    OT

  • Problem in printing the amount in one line in script

    Hi friends,
    iam facing a problem in scripts
    1st line: fifteen lakh thirty th
    2nd line : ousand three hundred
    instead i need in this way
    1st line: fifteen lakh thirty thousand
    2nd line :  three hundred
    ie if the line is not suffienct and if its breaking the word, it should not do that.
    it should not break the word it should print in next line.
    I dnt want the text in one line..
    I want to split when the there is a space before 35 chars in first line
    How can i do that.
    Regards
    Priyanka
    Edited by: priyanka jain on Feb 19, 2009 11:10 AM

    Hi,
    try giving the offset for the line.
    refer to this link:
    [Offset|http://help.sap.com/saphelp_47x200/HELPDATA/EN/d2/cb3d07455611d189710000e8322d00]/frameset.htm
    regards
    sarves

  • Problem with printing one variable in one line in smartforms

    Hi,
           Please help me.  It's my first time to use smartforms, and my problem is that I am trying to print one variable on one line and I just don't know why the variable splits and prints the other half on the next line.  On my paragraph format, I only chose the "Left-aligned" as my alignment choice and line spacing as one.  I used a character format for the variable just to make it bold.  The width of the window is 19.9cm.  Please, really hope someone could help me.  Thanks.
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Oct 13, 2009 9:16 AM

    Yes.  There are actually 3 variables on that window:
    SURNAME   <E1>&wa_surname(C)&</>
    FIRSTNAME <E1>&wa_fname(C)&</>
    MIDDLE NAME <E1>&wa_midname(C)&</>
    The variable for the firstname is the one being split to the next line.  It's like half of the firstname is combined with the middlename as shown in the example:
    FIRSTNAME    FIRST
    MIDDLE NAME NAME MIDDLE NAME
    When it should be:
    FIRSTNAME    FIRST NAME
    MIDDLE NAME MIDDLE NAME
    Thanks.

  • Problems with sending emails from my Blackberry BIS account - all on one line

    I am using a BB Storm 9500 and have been trying to use the BIS email account.
    However, whenever I reply or forward emails from my device, the email comes out all on one line regardless of the punctuation I put in.
    My signature also appears on one line despite having formatted it differently.
    I've seen some post on this problem before but I wondered whether anyone has resolved it now. It's a pain because when responding to work emails it looks completely unprofessional.
    Cheers
    TJE

    anyone try it? any use?
    dc

  • Why is my entire XML file all on one line?

    I am createing a XML file using DOM. The file is started as a new document and I add child nodes using the appendChild() function. I am also using the transformer class to write the file. The file output is as follows:
    <?xml version="1.0" encoding="UTF-8"?><TestSystems><department>Tape<program>T10000A</program></department></TestSystems>
    and I want it to be:
    <?xml version="1.0" encoding="UTF-8"?>
    <TestSystems>
    <department>Tape
    <program>T10000A</program>
    </department>
    </TestSystems>
    How can I get a nicely formated file?
    Here is my code:
    import java.io.*;
    import javax.xml.parsers.*;
    import javax.xml.xpath.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.dom.DOMSource;
    public class XMLTestClass {
        DocumentBuilderFactory domFactory;
        DocumentBuilder domBuilder;
        Document xmlDoc;
        String xmlFile = "c:\\test.xml";
        /** Creates a new instance of XMLTestClass */
        public XMLTestClass() {
            try{
                domFactory = DocumentBuilderFactory.newInstance();
                domBuilder = domFactory.newDocumentBuilder();
                //xmlDoc = domBuilder.parse(new File(xmlFile));
            //    xpath = XPathFactory.newInstance().newXPath();
            }//try
            catch (ParserConfigurationException e) {
                System.err.println("ParserConfigurationException caught...");
                e.printStackTrace();
        public void run(){
            System.out.println("Test");
            xmlDoc = domBuilder.newDocument();
            Element rootElement = xmlDoc.createElement("TestSystems");
            xmlDoc.appendChild(rootElement);
            Element deptElement = xmlDoc.createElement("department");
            deptElement.appendChild(xmlDoc.createTextNode("Tape"));
            rootElement.appendChild(deptElement);
            Element progElement = xmlDoc.createElement("program");
            progElement.appendChild(xmlDoc.createTextNode("T10000A"));      
            deptElement.appendChild(progElement);   
            try{
                TransformerFactory tf = TransformerFactory.newInstance();
                Transformer transform = tf.newTransformer();
                Source src = new DOMSource(xmlDoc);
                Result dest = new StreamResult(new File(xmlFile));
                transform.transform(src, dest);
            catch(Exception exp){}
        public static void main(String[] args){
            XMLTestClass xml = new XMLTestClass();
            xml.run();
    }

    Thanks for the tip. The code sort of works now but the funny thing is that the file output does not indent, but is no longer on one line. The out put is now (no indents):
    <?xml version="1.0" encoding="UTF-8"?>
    <TestSystems>
    <department>Tape<program>T10000A</program>
    </department>
    </TestSystems>
    Also the line
    transform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    [\code]
    does not seem to have any affect.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • INDESIGN GLITCH: Creating an XML file from Indesign Layout - Issue "Using more than one line of GREP" & "Map Styles to Tags"

    I currently create XML from InDesign CC by Mapping Style to Tags.
    - The Paragraph Styles are manually apply to text. These styles include multiple lines of GREP to automatically apply character styles.
    - I map some of the paragraph and character styles to prebuilt tags that have the same name "Map Styles to Tags".
    I have found through trouble-shooting that InDesign is unable to "Map Styles to Tags" for more than one line of GREP. I therefore have to chose which line of GREP to automatically tag and which lines to manually tag.
    Please can anyone help, I need to automatically map tags to at least two character styles in one paragraph via GREP.
    Thanks,

    OK. The best I can suggest is running a Find/Change like this:
    Which will actually apply the character style to the italics (and I would do the bold as well just to make certain). Then run the Map Styles to Tags again, using the Apply by Name. Which will tag the italics.
    I don't know why ID can map to the bold and not the italic character style. It either should do them both (as in this instance) or none at all as the character styles are not actually applied by the grep, just the styling from the character styles.
    Mike

  • HTML code displays on one line in browser view source

    Hi,
    In Dreamweaver, my HTML code displays returns, spaces, etc. However, in the view source option in a browser (Firefox in particular), all the code is displayed on one single line. I only found about this because I was having problems with my Google Ads not displaying. (A Google customer service person helped me to find a workaround for this since I still haven't figured how to get my code to display correctly.) So I have gone to Preferences in DW and changed my Code Format Line Break type. The result is the same with each of the three options: the code is all on one line when you check it under view source in a browser. (The server is Linux.)
    Does anyone know how to fix this? Also, I think I know how this happened in the first place. I copied my code to TextEdit for a quick backup the other day, and then I pasted it back to DW. Bad idea? Is the only way to get the code back to normal to re-write it in a new HTML file in DW?

    Pssh. Problem solved, but I'm not quite sure how. I did go back and try to clean up some redundant CSS and other things, but the HTML/CSS validator still shows that I have this one invalid <header> tag (www.nextmontenegro.com), but since that was written as part of the DW template, I just left it. Weird. Anyway, the code flows down the page now.
    Thanks for the quick replies and helpful hints:-)

Maybe you are looking for

  • "Print" button on ic-web client

    Hi Experts, We are working on SAP CRM 2007 On top of the page we see a Toolbar with several buttons. One of the buttons is print. (Used to print the contents of a view) Can anyone guide me where exactly is the code for this 'Print' event?? Which view

  • ICould calendar week view on iMac

    Why doesn't my iCloud Calendar advance to the next week in the week view?  It use to.  It will still advance in the day or month view.

  • How to create a PDF that prints at actual size for all printers

    I create printable educational products for teachers and homeschoolers.  I need to be able to make some printable PDFs that have cards set to a specific dimension, say 3" x 3".  When I create PDFs in InDesign and print them, the printer tends to shri

  • How to access EBO Designer in AIA 3.0

    HI, I have installed AIA 3.0. But when i login , i only see CAVS, Project Lifecycle and Setup. How can i access EBO Designer? THanks Manish

  • Folders in Screen Painter

    hello, i wonder how the folders (tabs) in bo work. when i add a folder it is drawn as an frame but not with tabs that i can give a caption. what is the logic behind the pane levels? which level do i have to set for the folder? which levels do i have