File concatenating program does not work

Hello, im quite new to java therefore it may only be a simple solution.
The program reads mulitple files off the command line and then should join them up (concatenate) in a new file called "NewFile".
The problem is it only prints the content of one of the files to the new file.
Here is my code:
/*Write an application which concatenates files. The name of
*each file is supplied on the command line. The output file
*consists of all the contents of the first file, followed by
*all the contents of the second file, and so on. One of the
*slides in the lecture may help.
import java.util.*;
import java.io.*;
public class Concatenate
     public void process (String[] argStrings) throws Exception
          String fileName = argStrings[0];
          String contents = null;
          System.out.println();
          System.out.println("Conatenated contents of files:");
          System.out.println();
          for (int index = 0; index < argStrings.length; index++)
               Scanner sc = new Scanner(new File(argStrings[index]));
               contents = sc.nextLine();
            System.out.println(contents);
               sc.close();
          PrintStream output = new PrintStream("NewFile.txt");
          output.println(contents);
        output.close();
}Thanks anyone
John

// put this before the for loop
PrintStream output = new PrintStream("NewFile.txt");
// put this inside the for loop
output.println(contents);Now, do you understand why you have to do that?

Similar Messages

  • TS1702 Maps program does not work. In standard it only shows a grid. If I ask for a route it shows start and end point and three route boxes but nothing else. It does show directions. If I switch to hybrid it shows to routes but no roads. Background is a

    Maps program does not work. In standard it only shows a grid. If I ask for a route it shows start and end point and three route boxes but nothing else. It does show directions. If I switch to hybrid it shows to routes but no roads. Background is a blur.

    Do you have a question? This is a user to user help forum. Apple is not here only other users like yourself. You don't report problems to Apple here.
    By the way, it might help if you indicated where you are located.
    To complain to Apple use http://www.apple.com/feedback/ipad.html

  • I just signed up for a subscription to adobe reader paying EUR 24.40. The program does not work, and I can not even go to my personal page .... help ...?

    I just signed up for a subscription to adobe reader paying EUR 24.40.
    The program does not work, and I can not even go to my personal page .... help ...?

    Adobe Reader is free; it does not require a subscription.
    Did you subscribe to an online service like ExportPDF, PDF Pack, ...?
    What exactly does "not work" mean?

  • Hello Since yesterday evening. My itunse program does not work my mobile. Note  I update the program to ios7 Please help me Thank you

    hi
    Hello
    Since yesterday evening. My itunse program does not work my mobile.
    Note
    I update the program to ios7
    Please help me
    Thank you

    I found this strange glitch that wouldn't let me open my iTunes Store. I tried all the reset options and still iTunes would close a second after it opened. I fixed this. Instead of using the iTunes Store icon on your home page to open it. Go into music and click on store. It will say "Cannot Connect To Store". Just tap ok. Then tap on "featured" on the bottom of the screen. That will take you to the store front page. After that is loaded. Back out and the icon for iTunes Store on the home page should work just fine. Hope that helps.

  • I purchased a program on Mac App store and the program does not act as it should,  also was required to pay up front whereas had I went to the web site, ibank 4 I would have had 30 days free trial an would have found that the program does not work.?

    I purchased a program on Mac App store and the program does not act as it should,  also was required to pay up front whereas had I went to the web site, ibank 4 I would have had 30 days free trial an would have found that the program does not work.?

    Free trials are not available through the Mac App Store.
    Apple is not here. Apple does not answer questions here. This is a user to user support forum. There are only folks here who use Apple products.

  • Now a few of programs does not work with mountian lion. what to do?

    now a few of programs does not work with mountian lion. what to do?

    espons printer/scanner, toast titanum 5.2.1, intuos 4 wacom, appleworks, already updated ms office & order the upgrade for reunion which I hope it will work. 
    thank you mr michael allbritton for your help!

  • My program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.  I uninstalled the program and reinstalled again but nothi

    my program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.
    I uninstalled the program and reinstalled again but nothing gone better-
    What should I do?
    Best regards

    Do you have Logitech gaming software installed on the PC? If so, perhaps try the suggestion from the following post:
    Re: Everytime I close Itunes it loads back up

  • Help with util.zip up files... does not work

    I am writing a program so my mum can zip up new photos she takes and then send them to me. The program creates a html file for the webpage plus a smaller version of her original photo and places them all in a 1 folder with a new name. Al this part works... I want to afterwards place my files in a zipped up folder that she can e-mail me with her normal client. How... I picked up this code on the net and have changed it to incoporate my parameters. The files which are created ..paths are (String in an String[]) I then send to my zipping method.
    The zip file is created but does not work when I try to extract from it ??? I also know that the String [] works becuse I have made a loop to check its properties at each index.
    what am I doing wrong?
    This is a modified code I found on the internet but with no author??
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.*;
    public class Test{
        private File zipDir;
        private String[] filename;
        public Test(String[] recivedFilename){
            filename = recivedFilename;
            try {
                ZipOutputStream zos = new
                        ZipOutputStream(new FileOutputStream("c:\\curDir.zip"));
                from,
                zipDir("c:\\batviapictures\\", zos);
                zos.close();
            } catch(Exception e) {
                //handle exception
        public void zipDir(String dir2zip, ZipOutputStream zos) {
            try {File
                zipDir = new File(dir2zip);
                String[] dirList = filename;
                byte[] readBuffer = new byte[2156];
                int bytesIn = 0;
                //loop through dirList, and zip the files
                for(int i=0; i<dirList.length; i++) {
                    File f = new File(zipDir, dirList);
    if(f.isDirectory()) {
    String filePath = f.getPath();
    zipDir(filePath, zos);
    continue;
    FileInputStream fis = new FileInputStream(f);
    ZipEntry anEntry = new ZipEntry(f.getPath());
    zos.putNextEntry(anEntry);
    while((bytesIn = fis.read(readBuffer)) != -1) {
    zos.write(readBuffer, 0, bytesIn);
    fis.close();
    catch(Exception e) {

    I make no guarantees that this will completely solve all your problems, but I just know these calls are needed but missing from your OP:
    try {
        ZipOutputStream zos = new
                        ZipOutputStream(new FileOutputStream("c:\\curDir.zip"));
                        from,
                        zipDir("c:\\batviapictures\\", zos);
        zos.flush(); // ADD THIS after all files have been written to the zos
        zos.close();
    } catch(Exception e) {
        //handle exception
    }And
    while((bytesIn = fis.read(readBuffer)) != -1) {
        zos.write(readBuffer, 0, bytesIn);
    zos.closeEntry(); // ADD THIS after each file is written to the zos
    fis.close();

  • Program does not work after build

    Hi,
    I have built a program today that builds fine (no errors or warnings) but it fails when running the exe.  I am using drivers for a spectrum analyzer (Rohde & Schwarz FSG) and when one of these drivers is called, it returns an error.  Other drivers are run before this particular vi.  Anyone have any idea how to troubleshoot this?  I'm going to try and build the vi on its own and see if it works.  In the mean time, if anyone has any suggestions, please let me know.
    UPDATE: I built the file on its own and it still does not work.  Again, when I run it in developer mode, it works fine.
    VISA Write in rsspecan_core_write.vi->rsspecan_core_attribute_wr​ite_int.vi:3->subrsspecan_core_attribute_express.v​i:2->rsspecan Configure Averaging Type.vi:Instance:Instance           1 41Saved   rsspecan Configure Averaging Type .vi:1->rsspecan Configure Averaging Type.vi
    Thanks.

    I've decided to post the vi since it is free to download.  If anyone has an FSG and wants to build this file and see if they can run it, please do so.
    Attachments:
    rsspecan Configure Averaging Type.vi ‏31 KB

  • Program does not Work

    I have a for loop in which I am reading the content of an array.Also a method is called within the for loop the purpose of this method is to be able to jump to a another array index.
    I have written the program as shown below but it does not work.
    private class Executionionhandler implements ActionListener
    { public void actionPerformed(ActionEvent event)
    { for(int i=0;i<62;i++)
    { int x=array[i];
    int k=x+2;
    look(x);
    public void look(int j)
    { if(j==0)
    button.setText(�Readyl�);
    else if(j=1)
    button.setText(�Go�);
    else if(j=2)
    button.setText(�Stop�);
    else if(j==5)
    i=20;
    else button.setText(�Successful�);
    Any idea why or how can I achieve this?

    http://forum.java.sun.com/thread.jsp?thread=265406&forum=31&message=1006380
    http://forum.java.sun.com/thread.jsp?thread=265328&forum=31&message=1006048
    http://forum.java.sun.com/thread.jsp?thread=265310&forum=31&message=1005982
    http://forum.java.sun.com/thread.jsp?thread=265307&forum=31&message=1005979
    http://forum.java.sun.com/thread.jsp?thread=265307&forum=31&message=1005969

  • Encryption program does not work in IBM JDK

    Hi
    I have a encrypt, decrypt program, which does not work in IBM JDK
    the code is as below, it gives PBEWithMD5AndDES does not exist kind of error when running with IBM JDK
    import java.io.UnsupportedEncodingException;
    import java.security.spec.AlgorithmParameterSpec;
    import java.security.spec.KeySpec;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.PBEParameterSpec;
    public class MapsPasswordUtil
         Cipher ecipher;
         Cipher dcipher;
         // 8-byte Salt
         byte[] salt = { (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
                   (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03 };
         // Iteration count
         int iterationCount = 19;
         public MapsPasswordUtil(String passPhrase)
              try
                   KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,
                             iterationCount);
                   SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES")
                             .generateSecret(keySpec);
                   ecipher = Cipher.getInstance(key.getAlgorithm());
                   dcipher = Cipher.getInstance(key.getAlgorithm());
                   // Prepare the parameter to the ciphers
                   AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,
                             iterationCount);
                   // Create the ciphers
                   ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
                   dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
              } catch (java.security.InvalidAlgorithmParameterException e)
                   e.printStackTrace();
              } catch (java.security.spec.InvalidKeySpecException e)
                   e.printStackTrace();
              } catch (javax.crypto.NoSuchPaddingException e)
                   e.printStackTrace();
              } catch (java.security.NoSuchAlgorithmException e)
                   e.printStackTrace();
              } catch (java.security.InvalidKeyException e)
                   e.printStackTrace();
         public String encrypt(String str)
              try
                   // Encode the string into bytes using utf-8
                   byte[] utf8 = str.getBytes("UTF8");
                   // Encrypt
                   byte[] enc = ecipher.doFinal(utf8);
                   // Encode bytes to base64 to get a string
                   return new sun.misc.BASE64Encoder().encode(enc);
              } catch (javax.crypto.BadPaddingException e)
                   e.printStackTrace();
              } catch (IllegalBlockSizeException e)
                   e.printStackTrace();
              } catch (UnsupportedEncodingException e)
                   e.printStackTrace();
              return null;
         public String decrypt(String str)
              try
                   // Decode base64 to get bytes
                   byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
                   // Decrypt
                   byte[] utf8 = dcipher.doFinal(dec);
                   // Decode using utf-8
                   return new String(utf8, "UTF8");
              } catch (javax.crypto.BadPaddingException e)
                   e.printStackTrace();
              } catch (IllegalBlockSizeException e)
                   e.printStackTrace();
              } catch (UnsupportedEncodingException e)
                   e.printStackTrace();
              } catch (java.io.IOException e)
                   e.printStackTrace();
              return null;
    }

    Works for me with the latest IBM JDK. You will need to specify your context i.e. what platform, what JDK/JRE etc etc etc.
    P.S. That exception handling is rubbish.
    Edited by: sabre150 on Mar 23, 2009 6:01 AM
    I suspect that you are using JDK 1.5 and that you have fallen foul of the bug where key.getAlgorithm() does net return the correct value. You get round this by specifying it as             SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
                ecipher = Cipher.getInstance("PBEWithMD5AndDES");Of course if you are clever you will just define a static final constant for this algorithm.
    Edited by: sabre150 on Mar 23, 2009 6:09 AM

  • My java programe does not work

    Hi
    I createda java programme with jdeveloper . I compiled my code in all of version (1.3, 1.4, 1.5, 1.6 and default).
    But when i try to run my programme in other computers that have j2SE Runtime Environment 5.0 update 11, or java Runtime 2 Environment SE 1.3 - 1.4,
    my programme doesnot work.
    how can i fix this problem.

    Which Jdev version?
    What exactly do you mean by 'does not work'?
    Timo

  • PI 7.30: OS command on AIX to archive files on FTP does not work

    Dear experts,
    Our PI system runs on an AIX server.
    I have a scenario PI --> FTP. I also need to archive files in a seperate folder on the FTP.
    I have been following thread:
    Read or Write File On FTP server based on another file existence.
    After file processing in the Audit Log in RWB I among others I get the information:
    Execute OS command "sh /usr/sap/SYS/flex/batches/archive.sh file.zip /ftpfolder/file.zip"
    It seems it is working properly.
    The file itself gets processed to the "ftpfolder". But in the archive folder I do not get a copy of that file.
    My script looks like this:
    #!/bin/ksh
    ftp -n -v <<%%EOF%%
    open ftpserver
    user myuser mypassword
    prompt
    asci
    cd archivefolder
    mput $2
    bye
    %%EOF%%
    In the file receiver I have "Run OS command after message processing":
    "sh /usr/sap/SYS/flex/batches/archive.sh %f %F"
    %F stands for the complete path, right? So if I say "mput $2" in my script it should use %F.
    Could you please help me out here. I really don't know what the problem could be.
    Thank you and best regards,
    Peter

    hi Peter,
    >>>I have a scenario PI --> FTP
    but FTP does not support OS command as far as I remember
    correction:
    "Note that for the File Adapter transport protocol "FTP", the operating system command is NOT executed on the FTP server, but on the server hosting the Adapter Engine."
    please check for details:
    Note 841704 - XI File & JDBC Adapter: Operating system command
    Regards,
    Michal Krawczyk
    Edited by: Michal_Krawczyk_PIXI on Feb 3, 2012 3:38 PM

  • Google documents - 'select files to upload' does not work with v 3.6.8 Firefox - several users have noticed this.

    Until Friday, I could upload documents using google's facility within Firefox . Suddenly, the 'select files to upload' stopped working. Internet Explorer does this ok.
    I noticed on the Google forum that several users have reported this and someone suggested it should be reported to Firefox as it works with other browsers. I am using Windows XP on a laptop.

    It is an issue that Google are aware of and are working on a solution. See [http://www.google.com/support/forum/p/Google+Docs/thread?tid=4f0369bdcf6fd7ff&hl=en "Select files to upload" not working in Firefox - Google Docs Help]
    (Thanks to Joolsa for the link)

  • Spotlight Not finding files Re indexing does not work

    As the title says really, but there is more.
    If I am logged in as one of two users, I can't find the file in the spotlight search, not quite...but if I log in as a new user, the file appears within a few characters being typed in the Spotlight of the new User.
    The File title is Su Birth Cert.jpg
    If I am logged in as that user, I have to type the filename and include the  (.)  full stop at the end just before the  'jpg'  I don't need to type as far as jpg, Just the Full stop  (.)
    It is a jpg file, stored in a "Documents' sub folder with other ID info.
    Images are checked in Spotlight Preferences...but it is an Image..in a Documents Sub folder.
    I thought that may have been an issue...so i moved some documents over to the "pictures" home folder.  Spotlight continued to find the Document in the Pictures folder.
    I Duplicated the Birth Cert image..Spotlight still could not find it
    I opened the Image in Preview and exported it as a PDF Spotlight can now find it iinstantly
    I have re index multiple times, Re booted, Safe Booted, Recovery booted (where the Menu bar would not work,  where the Menu bar wold not work)   RESET PRAM
    Dragged User Folders HDD to Spotlight Privacy, then deleted it so to Force Re indexing
    used the command from other threads tp reset user folder permissions.
    Disk Utility does not give the option to Repair Permissions on the User Folders HDD.....yes the user Folders are 'moved' via the Sys prefer /Users/ Advanced options, to a separate HDD.
    Any one have any ideas?
    Spotlight does just not seem to want to find some files.

    Spotlight won’t work

Maybe you are looking for

  • How do i make a jpeg flag look likes its waving

    i have a jpeg of a specific flag that i am trying to make it a loop. whats does it take to make the jpeg look like its waving in the wind? The only thing i have successfully done is put a ripple dissolve across the whole thing and it looks like... we

  • Where is the zion and female to male effe

    In x-fi where is it ? is it gone why?

  • How to save feathering in web and web/devices?

    I've scanned a page of handwriting, then used Photoshop CS4 to feather the border. But when I move the PSD to web and devices to compress and make the image a gif, I lose the feathered border> instead, I have a hard edge with rounded corners. Can som

  • Decoding an error text

    Hello, Sometimes when I try to read the text for an error mesage, all I see is just some code like "RSPC009". What does this code mean and what am I supposed to do with this? How do I solve my problem or atleast find a hint to solve it? Pls help. Poi

  • Ipod mini won't reset

    My Ipod mini won't reset. Help!