windows - Java - Unable to find a file path which certainly exists -


i sure relatively simple question, , think may more of problem windows java.

i have method copying file new directory, takes 2 file objects, file created path of original, , file created desired path of copy. sure method works because have used copy file onto desktop.

however, using actual desired path creates error:

java.io.filenotfoundexception: path (the system cannot find path specified)

where path path attempting use.

here guess: making program use on machine. such, path trying use is:

c:\users\xxxxxx\rest_of_path\filename.file

where xxxxxx primary user on machine writing program for.

this directory exists on system, xxxxxx not user on system. guessing windows causing problem because of that.

i'm changing code use solution depends on machine, , not hardcoded (system.getproperty).

however, i'd know why problem occurring, academic standpoint, windows , java user.

thanks in advance.

edit: accidentally used forward slashes when meant double backslashes. ensure not spelling error, copied directory using windows, , pasted program (then doubled on backslashes).

edit: several users have suggested far more clean trying in first place. i'm leaving question open because i'm curious why not working.

edit: used solution above , i'm happy it. still don't know why windows not allow me access original path, guess don't care @ point. thanks, everybody!

in java, , programming languages, don't have provide exact directory of file. although nice see code you're using file, i'll provide how can done.

i'm assuming aren't using new file("file.txt") because retrieves files folder program in, , doesn't require entire address c:\...\...\.... don't want use entire address because different operating systems use different paths, obviously.

the best can put files , requested folders somewhere relative program (whether it's class files or .jar file).

but windows can sure system.getproperty("...") can retrieve directory urls relative paths files/folders.

documentation on system.getproperty here: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

i may not have helped or answered question @ all. you'll find solution.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -