Results 1 to 14 of 14
Thread: not reconizing path
- 07-29-2011, 03:07 AM #1
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(); } } }Can anyone suggest how i can fix this?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)
- 07-29-2011, 03:43 AM #2
First question - Is there anything incorrect about the error message?FileNotFoundException: /home/User/Desktop/file.txt (No such file or directory)
- 07-29-2011, 05:24 AM #3
Code Conventions for the Java(TM) Programming Language: Contents
Class names should start with an uppercase letter.
db
- 07-29-2011, 11:10 PM #4
@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 errorLast edited by sublixt; 07-30-2011 at 02:43 PM.
- 07-29-2011, 11:19 PM #5
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./home/User/Desktop/file.txt (No such file or directory)
- 07-29-2011, 11:24 PM #6
there is a file in that directory that was the first thing that i checked to make sure that wasn't the error.
- 07-29-2011, 11:26 PM #7
Do the spellings match exactly with those in the message?
- 07-29-2011, 11:32 PM #8
in a terminal i cd to the directory and it went there just fine. its a ubuntu linux directory if that helps.
- 07-29-2011, 11:48 PM #9
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)
- 07-29-2011, 11:51 PM #10
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.
- 07-30-2011, 12:17 AM #11
i figured it out after my long talk with a few friends thanks for the help
- 07-30-2011, 12:18 AM #12
And you're not going to tell us?
- 07-30-2011, 12:39 AM #13
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.
- 07-30-2011, 12:44 AM #14
Similar Threads
-
Which path to take?
By clschalkwyk in forum New To JavaReplies: 4Last Post: 04-06-2011, 10:18 AM -
setting class-path & Library Path in ubantu
By programmer_007 in forum EclipseReplies: 18Last Post: 02-22-2010, 12:31 PM -
os path
By anilkumar_vist in forum New To JavaReplies: 1Last Post: 01-07-2010, 09:05 PM -
how to set path ?
By Emy in forum Advanced JavaReplies: 2Last Post: 10-07-2009, 07:32 AM -
Where should this path be?
By Abder-Rahman in forum Advanced JavaReplies: 1Last Post: 02-16-2009, 07:13 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks