I need help with copying files in java?

hi, i use the following code sample to copy a directory structure and its files.
It copy's the directory-structure, but all the files in it have 0kb as size. except one file.
Here's the code:
public static void copyDir(String source, String target)
String [] listing = new String [0];
FileReader in = null;
FileWriter out = null;
String sourcePath = source;
String targetPath = target;
// Maakt directory onder target directory
File f = new File(targetPath);
f.mkdir();
// Maakt filelist van bestanden in source-directory
f = new File(sourcePath);
listing = f.list();
for(int i = 0; i < listing.length; i++)
f = new File(sourcePath + listing);
if(f.isDirectory())
copyDir(source + listing[i] + File.separatorChar,
target + listing[i] + File.separatorChar);
else
try
in = new FileReader(sourcePath + listing[i]);
out = new FileWriter(targetPath + listing[i]);
int t;
while (-1 != (t = in.read()))
out.write(t);
try { Thread.sleep(200); } catch (InterruptedException e) { }
System.out.println("Copied: " + sourcePath + listing[i]);
catch (Exception e)
System.out.println(e);

Here is a quick copy program that works. You'll need to deal with the exception instead of just throwing it though.
import java.io.*;
public class Copy
  private static void copy(String source, String target) throws IOException
    // Create directory
    File file=new File(target);
    file.mkdirs();
    // Get contents
    file=new File(source);
    File[] files=file.listFiles();
    // Copy files
    int length;
    byte[] buffer=new byte[1024];
    for(int i=0; i<files.length; i++)
      String destination=target+File.separator+files[ i ].getName();
      if(files[ i ].isDirectory())
        copy(files[ i ].getPath(), destination);
      else
        FileInputStream in=new FileInputStream(files[ i ]);
        FileOutputStream out=new FileOutputStream(destination);
        while((length=in.read(buffer))!=-1)
          out.write(buffer, 0, length);
        in.close();
        out.close();
  public static void main(String[] args) throws IOException
    copy(args[0], args[1]);
}[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Need help with copying files onto external drive

    I need help! Trying to copy downloaded movie files from Vuze (which have downloaded successfully) and copy onto external hard drive to view them but it wont let me copy over to the external device. Any ideas how to fix this please???

    Can you explain the steps you used, and the error message (or symptom), that says the copy did not work? 

  • Need help with connecting file inputs to arrays

    In this assignment I have a program that will do the following: display a list of names inputed by the user in reverse order, display any names that begin with M or m, and display any names with 5 or more letters. This is all done with arrays.
    That was the fun part. The next part requires me to take the names from a Notepad file, them through the arrays and then output them to a second Notepad file.
    Here is the original program: (view in full screen so that the code doesn't get jumbled)
    import java.io.*;       //Imports the Java library
    class progB                    //Defines class
        public static void main (String[] arguments) throws IOException
            BufferedReader keyboard;                                  //<-
            InputStreamReader reader;                                 //  Allows the program to
            reader = new InputStreamReader (System.in);               //  read the the keyboard
            keyboard = new BufferedReader (reader);                  //<-
            String name;                 //Assigns the name variable which will be parsed into...
            int newnames;               //...the integer variable for the amount of names.
            int order = 0;              //The integer variable that will be used to set the array size
            String[] array;             //Dynamic array (empty)
            System.out.println (" How many names do you want to input?");   //This will get the number that will later define the array
            name = keyboard.readLine ();
            newnames = Integer.parseInt (name);                                         // Converts the String into the Integer variable
            array = new String [newnames];                                               //This defines the size of the array
            DataInput Imp = new DataInputStream (System.in);       //Allows data to be input into the array
            String temp;                                       
            int length;                                                                  //Defines the length of the array for a loop later on
                for (order = 0 ; order < newnames ; order++)                                //<-
                {                                                                           //  Takes the inputed names and
                    System.out.println (" Please input name ");                            //  gives them a number according to
                    temp = keyboard.readLine ();                                           //  the order they were inputed in
                    array [order] = temp;                                                  //<-
                for (order = newnames - 1 ; order >= 0 ; order--)                                //<-
                {                                                                                //  Outputs the names in the reverse 
                    System.out.print (" \n ");                                                   //  order that they were inputed
                    System.out.println (" Name " + order + " is " + array [order]);             //<-
                for (order = 0 ; order < newnames ; order++)                                  //<-
                    if (array [order].startsWith ("M") || array [order].startsWith ("m"))     //  Finds and outputs any and all
                    {                                                                         //  names that begin with M or m
                        System.out.print (" \n ");                                            //
                        System.out.println (array [order] + (" starts with M or m"));         //
                    }                                                                         //<-
                for (order = 0 ; order < newnames ; order++)                                            //<-
                    length = array [order].length ();                                                   //
                    if (length >= 5)                                                                    //  Finds and outputs names
                    {                                                                                  //  with 5 or more letters
                        System.out.print (" \n ");                                                      //
                        System.out.println ("Name " + array [order] + " have 5 or more letters ");      //<-
    }The notepad file contains the following names:
    jim
    laruie
    tim
    timothy
    manny
    joseph
    matty
    amanda
    I have tried various methods but the one thing that really gets me is the fact that i can't find a way to connect the names to the arrays. Opening the file with FileInputStream is easy enough but using the names and then outputing them is quite hard. (unless i'm thinking too hard and there really is a simple method)

    By "connect", do you just mean you want to put the names into an array?
    array[0] = "jim"
    array[1] = "laruie"
    and so on?
    That shouldn't be difficult at all, provided you know how to open a file for reading, and how to read a line of text from it. You can just read the line of text, put it in the array position you want, until the file is exhausted. Then open a file for writing, loop through the array, and write a line.
    What part of all that do you need help with?

  • Need Help with .nnlp File.............A.S.A.P.

    I'm having a problem also with my JNLP file. I have downloaded the program onto one computer and that computer is using j2re1.4.2_04
    The other computers I believe are all running j2re 1.4.2_05
    I'm not sure if that's make a difference, but on the computer with j2re 1.4.2_05 when going to the site where the .jnlp file is located, the application comes up and says Starting Application. After it gets to that screen it just stays there. I really need help with this as soon as possible.
    Here is my .jnlp file listed below:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp
      spec="1.0+"
      codebase="http://www.appliedsolutions.com/placewiz"
      href="Placewiz.jnlp">
      <information>
        <title>Placement Wizard 4.0</title>
        <vendor>Applied Solutions, Inc.</vendor>
        <homepage href="index.html"/>
        <description>Placement Wizard 4.0</description>
        <description kind="short">Short description goes here.</description>
        <offline-allowed/>
      </information>
      <resources>
        <j2se version="1.4+"/>
        <j2se version="1.3+"/>
         <j2se version="1.5+"/>
        <jar href="Placewiz.jar"/>
      </resources>
      <security>
          <all-permissions/>
      </security>
      <application-desc main-class="com/asisoftware/placewiz/loader/Exec">
    </jnlp>

    This was due to a change in 1.4.2_05
    the main class attribute
    main-class="com/asisoftware/placewiz/loader/Exec">is wrong - it should be:
    main-class="com.asisoftware.placewiz.loader.Exec">this didnt seem to mater before 1.4.2_05, but some change in java since then caused this bad class specification to stop loading.
    /Andy

  • Need help with batch file for javac.exe and java.exe

    I have this in my batch file:
    c:\jdk1.3.1_05\bin\javac
    What symbol do I need to be able to run this from cprompt with any file following it

    Thanks could remember that for nothing

  • I need help with viewing files from the external hard drive on Mac

    I own a 2010 mac pro 13' and using OS X 10.9.2(current version). The issue that I am in need of help is with my external hard drive.
    I am a photographer so It's safe and convinent to store pictures in my external hard drive.
    I have 1TB external hard drive and I've been using for about a year and never dropped it or didn't do any thing to harm the hardware.
    Today as always I connected the ext-hard drive to my mac and click on the icon.
    All of my pictures and files are gone accept one folder that has program.
    So I pulled up the external hard drive's info it says the date is still there, but somehow i can not view them in the finder.
    I really need help how to fix this issue!

    you have a notebook, there is a different forum.
    redundancy for files AND backups, and even cloud services
    so a reboot with shift key and verify? Recovery mode
    but two or more drives.
    a backup, a new data drive, a drive for recovery using Data Rescue III
    A drive can fail and usually not if, only when
    and is it bus powered or not

  • Need help with backup files made by HP Recovery.

    So in 2011 I had made a post about a DV9 series HP laptop I had that I felt needed a harddrive. Well the laptop has been sold to a friend of mine and he has since fixed the issue it had. My curent deboggle is trying to deal with the 36GB of data it backed up onto an external USB powered harddrive. The information was saved from a system that ran Windows VISTA, on that same DV9 Pavilion. I have a new laptop and it's a Pavilion DV6 running windows 7. Is there some sort of 3rd party application or an uncommon HP utility that can open, run or modify. Specificaly I need to some files but not all, but if my only option is to extract all then that would be fine also. There is an executible in the backup folder but it doesn't extract anything it just locks up. 
    For the TLR portion, need to access backup files made on an older HP laptop with windows vista to a newer HP latop running windows 7.

    Terribly sorry for the post, I should have researched more before posting. I found the answer to my issue in another thread here on the HP forums! Thanks so much!!

  • Need help with fla.file

    Hi!
    I'm always having trouble with a fla.file in cs3 professional. Every time i try to reopen the file in flash i get this:
    failed to open document/users.desktop/jason/social.fla
    pls help reopen this file
    jay

    create a new directory and move your fla there and try and open.  if that fails, change the file's name and try and reopen.  if that fails and you created the fla, it's probably corrupt.

  • Help with copying files into the the Start Menu

    I am trying to copy my application which tracks system usage, such as reboots, temps, etc, I want it when it first runs, to copy it self into the the programs folder and the start up folder. However I get the error ""FileCopy: destination file is unwriteable: ""......Anyone have an idea why I get this error? Is there away around it? Thanks for any and all help
    *Copying on a Mac works fine
    *I am currently Testing it on a copy of Windows Xp
    *I havenot Tested Vista or 7 Yet.
    Hers the class which I call to copy my program
    class FileCopy {
         String OS="";
         String username;
         String dir;
         String name="Test.jar";
         String MAC="Mac OS X";
         String WinXp="Windows XP";
         String WinVista="Windows Vista";
         String Win7="Windows 7";
         JFrame errorWin;
         FileCopy(){
              System.out.println("Enter Copy");
              OS= ManagementFactory.getOperatingSystemMXBean().getName();
              username = System.getProperty("user.name"); 
              if(MAC.compareTo(OS)==0){
                   copyMac();
              else if(WinXp.compareTo(OS)==0){
                   copyWinXp();
              else if(WinVista.compareTo(OS)==0){
                   copyWinVista();
              else if(Win7.compareTo(OS)==0){
                   copyWin7();
              else
                   return;
         private void copyMac(){          
              System.out.println("Enter Mac Copy");
              System.out.println("OS:"+OS);
              String s="/Applications/Solitaire.Jar";
              try {
                   copy(name, s);
              } catch (IOException e) {
                   System.out.println("Failed at Mac Copy new");
                   errorWin=new JFrame("Error: Failed at Mac Copy new ");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
         private void copyWin7(){
              String dir1="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\SolitaireWin7.Jar";
              String dir2="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\SolitaireWin7.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   System.out.println("Failed at Win7 Copy 1");
                   errorWin=new JFrame("Failed at Win7 Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   System.out.println("Failed at Win7 Copy 2");
                   errorWin=new JFrame("Failed at Win7 Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         private void copyWinVista(){
              String dir1="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\SolitaireVista.Jar";
              String dir2="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\SolitaireVista.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at Winista Copy 1");
                   System.out.println("Failed at WinVista Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinVista Copy 2");
                   System.out.println("Failed at WinVista Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         private void copyWinXp(){
              String dir1="C:\\Documents and Settings\\"+username+"\\Start Menu\\Programs\\Solitaire.Jar";
              String dir2="C:\\Documents and Settings\\"+username+"\\Start Menu\\Programs\\Startup\\Solitaire.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinXp Copy 1");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                   System.out.println("Failed at WinXP Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinXp Copy 2");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                   System.out.println("Failed at WinXP Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         public void copy(String fromFileName, String toFileName) throws IOException {
           File fromFile = new File(fromFileName);
           File toFile = new File(toFileName);
           if (!fromFile.exists()){
                errorWin=new JFrame("FileCopy: " + "no such source file: "  + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "no such source file: "  + fromFileName);
           if (!fromFile.isFile()){
                errorWin=new JFrame("FileCopy: " + "can't copy directory: "
                           + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "can't copy directory: "
                 + fromFileName);
           if (!fromFile.canRead()){
                errorWin=new JFrame("FileCopy: " + "source file is unreadable: "
                           + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "source file is unreadable: "
                 + fromFileName);
           if (toFile.isDirectory())
             toFile = new File(toFile, fromFile.getName());
           if (toFile.exists()) {
             if (!toFile.canWrite()){
                  errorWin=new JFrame("FileCopy: destination file is unwriteable: " + toFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination file is unwriteable: " + toFileName);
             System.out.print("Overwrite existing file " + toFile.getName()
                 + "? (Y/N): ");
             System.out.flush();
             BufferedReader in = new BufferedReader(new InputStreamReader(
                 System.in));
             String response = in.readLine();
             if (!response.equals("Y") && !response.equals("y")){
                  errorWin=new JFrame("FileCopy: existing file was not overwritten.");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                  throw new IOException("FileCopy: existing file was not overwritten.");
           } else {
             String parent = toFile.getParent();
             if (parent == null)
               parent = System.getProperty("user.dir");
             File dir = new File(parent);
             if (!dir.exists()){
                  errorWin=new JFrame("FileCopy: destination directory doesn't exist: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination directory doesn't exist: " + parent);
             if (dir.isFile()){
                  errorWin=new JFrame("FileCopy: destination is not a directory: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination is not a directory: " + parent);
             if (!dir.canWrite()){
                  errorWin=new JFrame("FileCopy: destination directory is unwriteable: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination directory is unwriteable: " + parent);
           FileInputStream from = null;
           FileOutputStream to = null;
           try {
             from = new FileInputStream(fromFile);
             to = new FileOutputStream(toFile);
             byte[] buffer = new byte[4096];
             int bytesRead;
             while ((bytesRead = from.read(buffer)) != -1)
               to.write(buffer, 0, bytesRead); // write
           } finally {
             if (from != null)
               try {
                 from.close();
               } catch (IOException e) {
             if (to != null)
               try {
                 to.close();
               } catch (IOException e) {
    }

    That's clearly a security restriction then. You need to assign the JVM's user account enough rights to do so, or to configure any firewall/virusscanner which has possibly blocked it.
    Apart from this, are you aware of the fact that the OS root disk is not per se labeled "C:", that the location of documents is not per se "Documents and Settings", that there exist System#getenv() and System#getProperty() methods to find default system and environment variables and that there is the java.util.prefs API to access the registry? Your application is likely not going to run on any environment.

  • Need Help With Appleworks Files on New Macbook

    Hey Everyone,
    I had an old iMac blueberry with OS 9.2 using appleworks. I just bought a MACBOOK and i got iWORK and MS OFFICE 2004 installed on it. How can i get my appleworks files to open up on my new MACBOOK.
    please help
    -

    will Appleworks transfer and run on an INTEL based
    MAC?
    AppleWorks 6 is a "package" that contains both a Classic (Mac OS 9) application and an OS X application. The rest of what's essential to AppleWorks 6's operation is included in the other items inside the AppleWorks 6 folder. AppleWorks will generate all needed items outside this folder when it is run.
    The OS X application will operate (and operate well) on the intel based Macs using Rosetta, which is included with these machines. AW 6.2.4 and AW 6.2.9 (IN Mac OS 9, the version numbers on the splash screen and in About AppleWorks for these two are 6.2.3 and 6.2.8) are the most stable and least error prone in OS X; update before or after the transfer if you have earlier versions.
    Remember also that your AppleWorks license allows for only one copy to be installed on a computer. If you want to continue to use AppleWorks on the G3 iMac, you'll need to purchase a retail copy to install on the MacBook.
    Regards,
    Barry

  • Migrating from iMac CD to MBPC2D - Need Help with the FIle Migration

    I just ordered a refurb 2.4 MacBook Pro, which will replace my iMac Core Duo as my main machine. The iMac is running Tiger. I've decided that I only am concerned with migrating the following information from the iMac, and want some help on the best way to do this (paths/locations would be helpful too):
    -iPhone backups - to ensure my iPhone doesn't get wiped when it syncs. I will want to copy the last backup over to the MBP.
    -All iTunes Music and Movies
    I will then manually re-install VirusBarrier x4, MS Office, etc. I think this is better than trying to migrate everything over. What do you think?
    Edit: I also have a FireWire external hard-drive available to assist with this.
    Thanks
    Message was edited by: Azeroth

    Folders You Can Move to Your new Mac
    From the Home folder copy the contents of Documents, Movies, Music, Pictures, and Sites.
    In your /Home/Library/ folder:
    /Home/Library/Application Support/AddressBook (copy the whole folder)
    /Home/Library/Application Support/iCal (copy the whole folder)
    Also in /Home/Library/Application Support (copy whatever else you need including folders for any third-party applications)
    /Home/Library/Keychains (copy the whole folder)
    /Home/Library/Mail (copy the whole folder)
    /Home/Library/Preferences/com.apple.mail.plist (* This is a very important file which contains all email account settings and general mail preferences.)
    /Home/Library/Preferences/ copy any preferences needed for third-party applications, iTunes, iCal, Address Book, Safari.
    /Home /Library/iTunes (copy the whole folder)
    /Home /Library/Safari (copy the whole folder)
    If you want cookies:
    /Home/Library/Cookies/Cookies.plist
    /Home/Library/Application Support/WebFoundation/HTTPCookies.plist
    For Entourage users:
    Entourage is in /Home/Documents/Microsoft User Data
    Also in /Home/Library/Preferences/Microsoft
    For FireFox:
    /Home/Library/Applications Support/FireFox
    /Home/Library/Preferences/org.mozilla.firefox.plist
    Credit goes to another forum user for this information.
    Read the following about moving iTunes: iTunes- About Music Store authorization and deauthorization.

  • Deploying EJB EARs to Weblogic -- need help with descriptor file?

    I posted this in a different area... maybe it will help to post here.
    Hi all...
    Can someone give me a hand with getting the descriptor correct? I find lots of information about the structure of the XML file, but not much on what needs to go in it.
    If I deploy with it i the default state I don't get that error... but I can't dig my beans out with JNDI.
    I also notice that the class is not the generated class I would expect (and see on other deployments) but is "com.java.proxy.PROXY"
    Here is the top of my bean...
    package f17.ejb.creditdata;
    import javax.ejb.SessionContext;
    import javax.ejb.Stateful;
    @Stateful(name = "creditScoreData", mappedName = "f17.ejb.creditData-creditScoreData")
    public class creditScoreDataBean implements creditScoreData {
    This is my weblogic-ejb-jar.xml as it stands:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
                      xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar">
      <weblogic-enterprise-bean>
        <ejb-name>creditScoreDataBean</ejb-name>
        <stateful-session-descriptor>
          <business-interface-jndi-name-map>
            <business-remote>creditScoreData</business-remote>
            <jndi-name>creditScoreData</jndi-name>
          </business-interface-jndi-name-map>
        </stateful-session-descriptor>
        <ejb-reference-description>
          <ejb-ref-name>creditScoreData</ejb-ref-name>
          <jndi-name>f17.ejb.creditdata.creditScoreData</jndi-name>
        </ejb-reference-description>
        <jndi-name>f17.ejb.creditdata.creditScoreData</jndi-name>
      </weblogic-enterprise-bean>
    </weblogic-ejb-jar>

    I figure this out.. wanted to delete the thread.. but I can't find that option. lol

  • Need help with simple file sharing application

    I have an assignment to build a Java File Sharing application. Since I'm relatively new to programming, this is not gonna be an easy task for me.
    Therefore I was wondering if there are people willing to help me in the next few days. I will ask questions in this thread, there will be loads of them.
    I already have something done but I'm not nearly halfway finished.
    Is there a code example of a simple file sharing application somewhere? I didn't manage to find it.
    More-less, this is what it needs to contain:
    -client/server communication (almost over)
    -file sending (upload, download)
    -file search function (almost over)
    -GUI of an application.
    GUI is something I will do at the end, hopefully.
    I hope someone will help me. Cheers
    One more thing, I'm not asking for anyone to do my homework. I will only be needing some help in the various steps of building an application.
    As I said code examples are most welcome.
    This is what I have done so far
    Server:
    package ToJeTo;
    import java.io.*;
    import java.net.*;
    public class MultiServer {
        public static ServerSocket serverskiSoket;
        public static int PORT = 1233;
        public static void main(String[] args) throws IOException {
            try {
                serverskiSoket = new ServerSocket(PORT);
            }catch (IOException e) {
                System.out.println("Connection impossible");
                System.exit(1);
            do {
                Socket client = serverskiSoket.accept();
                System.out.println("accepted");
                ClientHandler handler = new ClientHandler(client);
                handler.start();
            } while(true);
    }Client:
    package ToJeTo;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.*;
    import java.util.Scanner;
    public class MultiClient {
        public static InetAddress host;
        public static int PORT = 1233;
        public static void main(String[] args) {
            try {
                host = InetAddress.getLocalHost();
            }catch (UnknownHostException uhe) {
                System.out.println("Error!");
                System.exit(1);
            sendMessages();
        private static void sendMessages() {
            Socket soket = null;
            try {
                soket = new Socket(host, PORT);
                Scanner networkInput = new Scanner(soket.getInputStream());
                PrintWriter networkOutput = new PrintWriter(soket.getOutputStream(), true);
                Scanner unos = new Scanner(System.in);
                String message, response;
                do {
                    System.out.println("Enter message");
                    message = unos.nextLine();
                    networkOutput.println(message);
                    response = networkInput.nextLine();
                    System.out.println("Server: " + response);
                }while (!message.equals("QUIT"));
            } catch (IOException e) {
                e.printStackTrace();
            finally {
                try{
                    System.out.println("Closing..");
                    soket.close();
                } catch (IOException e) {
                    System.out.println("Impossible to disconnect!");
                    System.exit(1);
    }ClientHandler:
    package ToJeTo;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class ClientHandler extends Thread {
        private Socket client;
        private Scanner input;
        private PrintWriter output;
        public ClientHandler(Socket serverskiSoket) {
            client = serverskiSoket;
            try {
            input = new Scanner(client.getInputStream());
            output = new PrintWriter(client.getOutputStream(), true);
            } catch (IOException e) {
                e.printStackTrace();
            public void run() {
                String received;
                do {
                received = input.nextLine();
                output.println("Reply: " + received);
                } while (!received.equals("QUIT"));
                try {
                    if (client != null)
                        System.out.println("Closing the connection...");
                        client.close();
                }catch (IOException e) {
                    System.out.println("Error!");
    }Those three classes are simple client server multi-threaded connection.

    Now the other part that contains the search function looks like this:
    package ToJeTo;
    import java.io.*;
    import java.util.*;
    public class User {
        String nickname;
        String ipAddress;
        static ArrayList<String> listOfFiles = new ArrayList<String>();
        File sharedFolder;
        String fileLocation;
        public User(String nickname, String ipAddress, String fileLocation) {
            this.nickname = nickname.toLowerCase();
            this.ipAddress = ipAddress;
            sharedFolder = new File(fileLocation);
            File[] files = sharedFolder.listFiles();
            for (int i = 0; i < files.length; i++) {
                listOfFiles.add(i, files.toString().substring(fileLocation.length()+1));
    public static void showTheList() {
    for (int i = 0; i < listOfFiles.size(); i++) {
    System.out.println(listOfFiles.get(i).toString());
    @Override
    public String toString() {
    return nickname + " " + ipAddress;
    User Manager:
    package ToJeTo;
    import java.io.*;
    import java.util.*;
    class UserManager {
        static ArrayList<User> allTheUsers = new ArrayList<User>();;
        public static void addUser(User newUser) {
            allTheUsers.add(newUser);
        public static void showAndStoreTheListOfUsers() throws FileNotFoundException, IOException {
            BufferedWriter out = new BufferedWriter(new FileWriter("List Of Users.txt"));
            for (int i = 0; i < allTheUsers.size(); i++) {
                    System.out.println(allTheUsers.get(i));
                    out.write(allTheUsers.get(i).toString());
                    out.newLine();
            out.close();
    }Request For File
    package ToJeTo;
    import java.util.*;
    public class RequestForFile {
        static ArrayList<String> listOfUsersWithFile = new ArrayList<String>();
        Scanner input;
        String fileName;
        public RequestForFile() {
            System.out.println("Type the wanted filename here: ");
            input = new Scanner(System.in);
            fileName = input.nextLine();
            for (User u : UserManager.allTheUsers) {
                for (String str : User.listOfFiles) {
                    if (str.equalsIgnoreCase(fileName))
                        listOfUsersWithFile.add(u.nickname);
        public RequestForFile(String fileName) {
            for (User u : UserManager.allTheUsers) {
                for (String str : User.listOfFiles) {
                    if (str.equalsIgnoreCase(fileName))
                        listOfUsersWithFile.add(u.nickname);
        public static List<String> getAll() {
            for (int i = 0; i < listOfUsersWithFile.size(); i++) {
                //System.out.println("User that has the file: " + listOfUsersWithFile.get(i));
            return listOfUsersWithFile;
    }Now this is the general idea.
    The user logs in with his nickname and ip address. He defines his own shared folder and makes it available for other users that log on to server.
    Now each user has their own list of files from a shared folder. It's an ArrayList.
    User manager class is there to store another list, a list of users that are connected with server.
    When the user is searching for a particular file, he is searching through all the users and their respective files lists. Therefore for each loop inside a for each loop.
    Now the problem is how to connect all that with Client and Server class and put it into one piece.
    GUI should look somewhat like this:

  • Need help with copy/paste in CSS

    Hey,
    I am 3 lessons into a Dreamweaver class so that is the extent of my knowledge. For some reason when I copy/paste code from one CSS sheet to another the code is present etc. but when I go back into the HTML file to view the changes, nothing happened. I verified the coding and they are all correct etc. When I cut and paste new code into an HTML file, it works no problem so why is it not accepting the changes in the CSS? It is not even happening when I copy and paste an image. The image has text with it and rules set up but when I copy/paste , the rules don't apply and it has to be reformatted etc. I have even taken the code and manually typed it into the CSS and still nothing. I am beyond stumped with this.
    Can anyone please shed some light on this? Thanks!!

    copy/paste code from one CSS sheet to another the code is present
    So, you confirm that the code you copied is now present in the alternate CSS file, right?
    but when I go back into the HTML file to view the changes, nothing happened.
    To understand this we would need to see a) the code that you pasted into the original CSS file, and b) the HTML on the page.  Can you paste those two snippets into a reply here?
    The remainder of your post suggests to me that you are pasting HTML into a CSS file.  You do know that is not going to work, right?

  • Need help with .mov files that won't open

    Here's the situation...
    I have 2 dvdr's with 4 .mov files on them. when i try to copy them to my desktop it tells me that
    "the finder cannot complete the operation because some data in "BonJovi_Who_SaysDV NTSC.mov" could not be read or written. (Error code -36)
    I have to gain access to these .mov files tonight or I'm gonna be a real shithead. I just got the discs fedex'd to me today so I didn't put it off til the last minute. Can anyone offer any possible solutions? If so, please help.
    Java

    Putting aside copyright issues in (naive?) belief you have a legitimate use of the material, your problem lies in the file or disk. One of them is either corrupt or not compatible with the drive you are trying to read it on. Try it on another computer (even a PC) and if you can read it on that computer make a new copy of the file on a new disk or a firewire drive (or USB stick if it fits).

Maybe you are looking for