Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By sublixt

Thread: not reconizing path

  1. #1
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default not reconizing path

    I'm writing a code to move file from one folder to another but its giving me an exception saying the test file is not found. here is the code and exception.
    Java Code:
    import java.io.*;
    public class moveFile{
    	public moveFile(){
    		String OS = System.getProperty("os.name").toLowerCase();
    		if(OS.indexOf("win")>=0)
    			System.out.println("not implimented");
    		else if(OS.indexOf("not implimented")>=0)
    			System.out.println("");
    		else if(OS.indexOf("nux")>=0||OS.indexOf("nix")>=0){
    			File n = new File("/home/User/Desktop/file.txt");
    			File destination = new File("/home/User/Desktop/test");
    			copyFile(n,destination);
    		}
    		else
    			System.out.println("Your operating system is not supported.");
    		}
    	public void copyFile(File a, File b){
    	InputStream inStream = null;
    	OutputStream outStream = null;
    	File afile = a;
    	File bfile = b;
     
        	try{		 
        	    inStream = new FileInputStream(afile);
        	    outStream = new FileOutputStream(bfile);
        	    byte[] buffer = new byte[1024];		 
        	    int length;
        	    while ((length = inStream.read(buffer)) > 0){		 
        	    	outStream.write(buffer, 0, length);		 
        	    }		 
        	    inStream.close();
        	    outStream.close();
        	    afile.delete();
        	    System.out.println("File is copied successful!");		 
        	}catch(IOException e){
        	    e.printStackTrace();
        	}
    	}
    }
    Java Code:
    java.io.FileNotFoundException: /home/User/Desktop/file.txt (No such file or directory)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(FileInputStream.java:137)
    	at moveFile.copyFile(moveFile.java:24)
    	at moveFile.<init>(moveFile.java:12)
    	at mainC.main(mainC.java:4)
    Can anyone suggest how i can fix this?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default

    FileNotFoundException: /home/User/Desktop/file.txt (No such file or directory)
    First question - Is there anything incorrect about the error message?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Code Conventions for the Java(TM) Programming Language: Contents

    Class names should start with an uppercase letter.

    db

  4. #4
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    @Norm no i copied the error report straight from the eclipse console
    @DarrylBurke i tried making the making the file name capital it did nothing to help my error
    Last edited by sublixt; 07-30-2011 at 02:43 PM.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default

    /home/User/Desktop/file.txt (No such file or directory)
    If this message is correct, then you must create the path and file as shown in the message so the program can find the file.

  6. #6
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    there is a file in that directory that was the first thing that i checked to make sure that wasn't the error.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default

    Do the spellings match exactly with those in the message?

  8. #8
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    in a terminal i cd to the directory and it went there just fine. its a ubuntu linux directory if that helps.

  9. #9
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    instead of using generic User i decided to test with my computers username it gave me a new error
    Java Code:
    java.io.FileNotFoundException: /home/****/Desktop/test (Is a directory)
    	at java.io.FileOutputStream.open(Native Method)
    	at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    	at java.io.FileOutputStream.<init>(FileOutputStream.java:160)
    	at MoveFile.copyFile(MoveFile.java:25)
    	at MoveFile.<init>(MoveFile.java:12)
    	at mainC.main(mainC.java:5)

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default

    Sorry, I don't have a linux system and am unable to do any tests.
    Change your program or write a simple program to write out a file and see where the file is written.
    Try several paths.

  11. #11
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    i figured it out after my long talk with a few friends thanks for the help

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default

    And you're not going to tell us?

  13. #13
    sublixt's Avatar
    sublixt is offline Member
    Join Date
    Jul 2011
    Location
    somewhere
    Posts
    37
    Rep Power
    0

    Default

    my path for the outStream was to a directory and i mistakenly thought that it created a new file in that directory but it needs a file to move the data into so i wrote in code to add a text file to the directory and rewrote the outStream directory to the new file.
    Fubarable likes this.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

Similar Threads

  1. Which path to take?
    By clschalkwyk in forum New To Java
    Replies: 4
    Last Post: 04-06-2011, 10:18 AM
  2. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  3. os path
    By anilkumar_vist in forum New To Java
    Replies: 1
    Last Post: 01-07-2010, 09:05 PM
  4. how to set path ?
    By Emy in forum Advanced Java
    Replies: 2
    Last Post: 10-07-2009, 07:32 AM
  5. Where should this path be?
    By Abder-Rahman in forum Advanced Java
    Replies: 1
    Last Post: 02-16-2009, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •