Create Files in new directory

Hi can create files using the code shown in the current working directory of my executable when this.filePath = "atext.xml". But if I change this.filePath ="c:\data\atext.xml" I get an error such as "System cannot find the path specified" true, the path hs not been created, but that is what I am trying to do. What do I need to change.?
try{
String fileName = new String();
fileName = this.filePath;
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter outFile = new PrintWriter(bw);
outFile.println(emptyXML);
outFile.close();
catch (IOException ioex){
System.out.println(ioex.getMessage());
System.exit(1);

Probably the message means that the c:\data directory doesn't exist. You can't create a file in a nonexistent directory, so you would have to create the directory first for that to work.

Similar Messages

  • Moving a functional jsp and jar file to new directory breaks import?

    Simply put - how can I "move" or "copy" a functional JSP directory from the root of my site to a subdirectory
    of the same site and have it continue to work?
    here are the details:
    I have a site where the functional JSP content resides like so ...
    c:\site\itworkshere\thetestfile.jsp
    c:\site\itworkshere\WEB-INF\web.xml
    c:\site\itworkshere\lib\thejarfile.jar
    c:\site\itworkshere\classes\props.properties
    but when I copy the"itworkshere" directory to c:\site\newdirectory\itworkshere
    and try to load thetestfile.jsp page in my browser, I get ...
    thetestfile$jsp.java:6: Package com.corporatename.module.io not found in import.
    I know that the module.io classes are in thejarfile.jar, but for some reason, now that I've put the files
    in a new directory, the import is failing (simple import directive in thetestfile.jsp) And - yes - the .jar
    file is there in the new subdirectory.
    I am a newbie with jsp and just need to copy the files to new location and have them continue to work.
    Do I have to recompile the .jar with some sort of adjustments? I poked around and I don't see any assumptions about the directory structure in the build. The behavior leads me to believe that the build is assuming something
    about its location in the directory tree.
    Hope this question is clear and I appreciate any direction you can provide to steer me where to look/modify
    the necessary changes so I can move the .jsp's and .jar and not break them.

    Thanks for the suggestions and insights. I have made some progress.
    a context path of "/newdirectory/itworkshere" and a docBase of "./newdirectory/itworkshere" has resolved
    the .jsp include problem.
    However this seems a bit counter-intuitive to me considering that the default root context which is "" stands
    at the appBase which in my case is C:\Site. Since the default does not explicitly refer to the "itworkshere" directory,
    I'd expect that the newly added Context element would not have to either ---- BUT --- it does require that I include "itworkshere" in the context path and docBase (where I would expect ./newdirectory would have been sufficient since the default works that way) ... am I missing something?
    Now I havethe next odd behavior - the Servlet which resides in "itworkshere\WEB-INF\lib" is not loading when I put the appropriate URL in --> /newdirectory/itworkshere/DataCrunchingServlet
    I checked the web.xml file and it has the appropriate servlet-name and url-pattern (relative references)
    Furthermore I did a test where I simply rename the original working instance directory and again --- the URL is failing to find the servlet!!! (and yes I stopped/started Tomcat) It is as if the servlet can only be found in the originally installed scenario.
    I am extremely puzzled that the behaviors seem to indicate an assumption about the path structure, but the web.xml file is set up correctly.
    Help help!!! and Thank you.l

  • Why can't create file under /home directory?

    I user solaris10, and login as root,I find I can't create any file or directory under /home directory! It say "operation not applicable" ,Why? I am puzzled it for a long time. Anyone could tell how to do it?
    Thanks

    For Solaris,
    /home is not an on-disk file system, it is a file system under the
    control of the automounter, and only the automounter can create
    directories/files in it.
    If you don't want the automounter to manage /home, then remove the
    "/home" entry from /etc/auto_master
    (and issue the command "automount -v" to force the file
    to be reread, or reboot).
    However, the typical setup for Solaris is to locate user's home directories
    in /export/home.
    Kapil Khanna

  • How to create file in current directory?

    In my JSP-page I tried to create some file in my current project directory but this file is created in C:\jakarta-tomcat-4.0.1\bin directory. I can do it using absolute path but I'd like to use relative path. Please help me.
    Thank you in advance.
    Qand.

    Try this:
    String filename = servletContext.getRealPath(request.getContextPath());Then take off the last part (after the last slash) and put on your temporary file name.
    It's a thought, anyway...

  • Creating files in user directory results in "Operation not permitted" error

    Hello everyone,
    I have a FileVault-secured home directory on my PowerBook G4 running OS X 10.4.6 which gives me some headache, as you can see from the following Terminal session:
    arepty-powerbook:~ arepty$ touch fubar
    touch: fubar: Operation not permitted
    I am definitely in the correct directory, logged in as the correct user, have enough free disk space and the directory has the correct permissions, as you can see below:
    arepty-powerbook:~ arepty$ pwd
    /Users/arepty
    arepty-powerbook:~ arepty$ whoami
    arepty
    arepty-powerbook:~ arepty$ id arepty
    uid=501(arepty) gid=501(arepty) groups=501(arepty), 81(appserveradm), 79(appserverusr), 80(admin)
    arepty-powerbook:~ arepty$ df -h | grep '/Users/arepty'
    /dev/disk2s2 74G 64G 11G 86% /Users/arepty
    arepty-powerbook:~ arepty$ ls -l /Users/ | grep arepty
    drwx------ 180 arepty arepty 6222 May 3 12:31 arepty
    Am I missing something here or is my FileVault-directory perhaps fubar? Thanks in advance for any help you guys might be able to give me.
    Cheers,
    Alex
    PowerMac G5 & PowerBook G4   Mac OS X (10.4.6)  

    That is good to know, but it will probably make it ever harder to locate the cause of this problem. In the meantime, I made a backup of my FileVault-enabled user directory on my PowerMac and reinstalled the operating system on my PowerBook. During the backup, I have encountered a couple of I/O errors so I'm guessing either the filesystem was damaged (and could not be completely repaired by Disk Utility, which I have tried) or the hard drive is damaged.
    Just to be on the safe side, I have ordered a new hard drive and exchanged it (wouldn't want to risk data loss with the old hard drive) and everything works perfectly again with a completely new user directory.
    I am still wondering what caused all this trouble though, since I want to avoid another incident like this in the future.

  • Error: "Failed to creat file in destination directory" ??

    When I'm trying to download the latest JDK? How do I fix this thx

    IM HAVING THE SAME DAMN PROBLEM! I NEED HELP 2!

  • Create a new directory in server with JSP

    Hi,
    How can I create a directory in server with JSP.
    File dir = new File("a");
    dir.mkdir();
    does not work. what do I do?
    best regards,

    Hi
    Check the following things.
    1. What is the path where you are creating the directory.
    2. Do you permissions to create file in that directory.
    3. do a delete on that filename if that exists just to be sure. isdeleted = filedir.delete(). Check the boolean flag isdeleted too.
    Thanx and Regards
    Aruneesh

  • How to create a file in current directory

    hi,
    I want to create a file in a current directory, But when i written following
    code then it cannot create file, How i will create file in current directory?
    Is there anyone who can help me?what will be the solution of this problem?
    Please give me solution
    String dir=application.getRealPath("/");
         int count;
         String filename="sample.txt";
         out.println(dir+filename);
         FileOutputStream fout=new FileOutputStream(filename);
         PrintStream p;
         p=new PrintStream(fout);
         p.print("1");
         p.close();with regards
    Bina

    hi,
    my problem is that my path is ok...but when i open file in this directory then
    it cannot open a file, is there anyone who can do it? When a user save data in server from remote
    area then what will be path of my code? how i will solve it? please give me
    solution.
    with regards
    bina

  • Create folder and move files to specific directory in AL11

    My requirement is to create a new folder in one of the existing directories in AL11 and move some files into it.
    I searched the forum and found this solution but it creates folder only in DIR_HOME directory.
    data: unixcom like rlgrap-filename.
    data: begin of tabl occurs 500,
    line(400),
    end of tabl.
    unixcom = 'mkdir mydir'. "command to create dir
    "to execute the unix command
    call 'SYSTEM' id 'COMMAND' field unixcom
    id 'TAB' field tabl[].
    I want the folder to be created in some other directory DIR_INTERFACES .
    Any suggestions are welcome ..

    Get complete path (physical path) using FM FILE_GET_NAME_USING_PATH.
    Default directory is DIR_HOME, hence it creates file in that directory...If you specify complete folder name, it will be created under that path..
    Concatenate mkdir
    space
    <physical path>
    mydir
    into unixcom.

  • LV 8.2.1 reinstallation error 1301: Cannot create file

    Hi,
    I was forced to uninstall LV 8.2.1 and reinstall it. When I'm reinstalling LV 8.2.1 I get an error message
    Error 1301. Cannot create file ". A directory with the same name already exists. Cancel the install and try installing to a different location.
    (Abort, Retry, Ignore).
    This error is somehow related to the fact that after uninstalling LV 8.2.1 LabVIEW 8.2 installation directory still remains with some stuff in the user.lib and other folders. I'm always using OpenG packages and I didn't uninstall them so that may be the reason. I also used DataAct class browser with LabVIEW.
    The problem is that I cannot uninstall my OpenG packages before I can get my LabVIEW installed again as VI Package Manager reposinsible for installing OpenG packages doesn't work without installed version of LabVIEW. And I cannot get my LabVIEW correctly installed because of this error. I can press ignore and the installation procedes but I don't know whet it didn't do because of the error.
    I guess this error is a bug in LV 8.2.1 isntaller so would some of NI application engineers help, please.
    For now I press Ignore.
    Tomi Maila
    Tomi Maila

    You will get this error if the installer is trying to install a file that has the same name as a folder at that location. For example lets say the installer has a file called "sample" that should go in LabVIEW\examples folder. Now lets say there was a folder called "LabVIEW\examples\sample". Windows wont let you copy that "sample" file in the same location that contains a "sample" folder. The failure is not an error in the installer.
    The problem with the 8.2.1 installer is that it is not telling you what file this failure occurred on. It is trying to, but the string is not formatted correctly and it just says "cannot create file ." The actual file name should be where the "." is.
    You can usually tell what file it failed on from the text above the progress bar where it says what file is being copied. The best way to see what failed was to get an installation log file.
    Naren Salem
    LabVIEW R&D

  • Is there a way to create a new directory or file in application install directory programatically

    Hi to all,
    Is there a way to create a new directory or file in
    application install directory programatically.
    I want a xml file to be created with in the application
    install directory programatically(not the application storage
    directory)
    I have used the following code snippet:
    var file:File = new File();
    file = File.applicationDirectory;
    file = file.resolvePath("assets");
    if(!file.exists)
    file.createDirectory()
    I am thrown an exception when using this .....Security
    Exception

    Thanks, but my main problem is to delete the locally stored
    data that is stored in the application storage directory when the
    application is uninstalled.
    The data is not being deleted automatically when the
    application is uninstalled, thats why I want to write some file to
    application directory.
    My application is remembering the login username and password
    even I uninstall the application and reinstall the next
    time.

  • How do i delete Older files from the directory before create a new file?

    Hi,
    How do i delete older files in a particular directory,
    the senorio is count the number of .txt files in a directory and delete the older files if file count is more than 10. (if i add 11th file the very first file has to be deleted)
    i have written the code to count the files and delete , but it is deleting all the files instead of older file
    public class ExtensionFilter implements FilenameFilter {
      private String extension;
      public ExtensionFilter( String extension ) {
        this.extension = extension;            
      public boolean accept(File dir, String name) {
        return (name.endsWith(extension));
    public class FileUtils{
      public static void main(String args[]) throws Exception {
        FileUtils.deleteFiles("c:/countfile/", ".txt");
      public static void deleteFiles( String directory, String extension ) {
        ExtensionFilter filter = new ExtensionFilter(extension);
        File dir = new File(directory);
        String[] list = dir.list(filter);
        File file;
        if (list.length == 0) return;
        for (int i = 0; i < list.length; i++) {
          //file = new File(directory + list);
    file = new File(directory, list[i]);
    if ((list[i]).length()>=10)
         System.out.print(file + " deleted : " + file.delete());
    Thanks,
    Jamin Rosina                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    What your code is doing now, is deleting all filenames that are longer than 10 characters.
    Your problem lies in the line:
    if ((list).length()>=10)

  • Creating a file in different directory.....

    i have program that uses File class from Java IO package for creating a text file. I have written this program in c:\test\proj and i am running the program in that location. So obviously text file is created in the same directory...
    But the information from this text file is required for my servlet that runs on web server tomcat 4.1..so i have to manually copy this file and place this on the required directory...i have written program to create the same file on in C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples this directory but this is not happening..I reckon this is because of the spaces in the directory names....
    my problem is i am running program on c:\text\proj directory and i want text file to be created in C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples...
    the statement i am using to create a file is...
    File f = new File("C:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/ping.txt");
    do i have to modify the statment????
    please provide me with a solution...
    thanx

    You must be getting an IOException of some description when you open the output stream to the File.
    Or else you're looking for your file in the wrong place ...

  • Creating/replacing a file in a directory, without a prompt or error

    I am attempting to do something fairly simple in LabView but it seems that there must be an easier or more elegant way than the way I am doing it. 
    I have the main .vi running in c:\programs and it calls another .vi in the same directory.  In this subVI the program creates/replaces tags.dat in the c:\programs\data directory.  I want the file to be created if it doesn't exist or replaced if it does exist.   If the \data directory doesn't exist, I want it created.  And also I want the .vi to run in any directory and as a .exe or as a .vi.  This is what I am doing to accomplish this:
    1) Use App.kind, "Current VI's Path" and a case statement to strip once if it is "development system" and twice if it is "run-time system".
    2) Then use "LIST Directory" and a "For Loop" to look for "data" directory.  If it exists, do nothing, if it does not use "New Directory" to create it. 
    3) Use "LIST Directory" and a "For Loop" to look for "tags.dat" in \data directory.  If it exists use "Delete" to delete the file, if it does not exist, do nothing.
    4) Use "Open/Create/Replace File" with it set to "create or replace" to create tags.dat in the \data directory.
    Shouldn't the "Delete" file VI delete a file if it exists, but do nothing if it does not exist?  Instead, if the file doesn't exist, it causes an error.  The same goes for the "New Directory".  It should create the new directory, unless it already exists.   Also is there a way "open/create/replace" with it set to "create or replace" will not prompt the user to ask them if they want to delete the file (if it already exists)?  This is why I have to look for the file first, then delete it if it exists. 

    Are the "C:\programs" and "C:\programs\data" directories fixed, or are they based on the location of the VI/application. Your post seemed to be say both. If they're fixed you obviously don't need to use "Current VI's path".
    You might be able to save yourself some coding by using the OpenG function "Create Dir if Non-Existant.vi" and give it the path ""C:\programs\data" - it will create both directories if they're not there. This VI is part of the OpenG File I/O library. You mentioned that you were going to create an .exe, so if you decide to use this please note the distribution requirements for this VI.
    Also, I'm not understanding why you're deleting the file if you're specifying the "Open/Create/Replace File" VI do a "create or replace". In general, I tend to stay away from that VI since, frankly, it's a mess. You should be able to accomplish the same thing by using the "New File" function for "C:\programs\data\tags.data" with "overwrite" set to True.

  • How to create a new directory?

    Hi!
    I want to export each Layer to a png file in a directory named like the file.
    That directory is not exisiting.
    var document = app.activeDocument;
    folder = document.fullName+"-png";
    var file = new File(folder+"/"+layer.name+".png");
    document.exportFile(file,ExportType.PNG24,options);
    leads into an error that "documentname-png/" is not found.
    How do I create the directory 'document.fullName+"-png"'

    Thanks, that was exactly what I searched for.
    (I use a folder to go around the 31 character file length warning:
    http://www.electrictoolbox.com/change-adobe-photoshop-filename-compatibility-options/
    "Some names of the files being saved will be truncate to 31 characters for compatibility with Macintosh browsers.")

Maybe you are looking for