wood burning stoves*
The moose likes I/O and Streams and the fly likes Create a file at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Create a file at runtime" Watch "Create a file at runtime" New topic

Create a file at runtime

Arch Tiwari

Joined: Feb 07, 2003
Posts: 6
Basically I would like to create and write to a file at runtime. The problem is basically doing the same on the UNIX server.
I have given the path/filename as an environment variable in web.xml & pass this variable as a parameter to the FileOutputStream instance. My problem is creating the file in the directory I require.
I have a directory structure as "/devel/logs/logs" on the unix platform which is outside the OC4J container. I am unable to access this directory.
Say I create the variable as -
"/devel/logs/logs/myapp.log" , on the Unix server, this throws a null pointer error. However, on my local m/c the same file gets created within- /devel/logs/logs
Now say I create the variable as -
"\devel\logs\logs\myapp.log" , on the Unix server, this creates a file by the name -- "\devel\logs\logs\myapp.log" under the OC4J home directory.
What I want to know is, how to I create a file in the
"\devel\logs\logs\" directory on the UNIX server.
Please note that this directory is outside the OC4J container and that since it is a UNIX platform I will not be able to give anything like "c:\devel\logs\logs"
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi Arch,
Your question is not terribly clear to me -- but I'll try to answer it, anyway (if you don't mind :-)
I believe you are using OC4J (I assume stand-alone version -- and not the one embedded in "JDeveloper" -- but I don't know what version number) running on a Windows machine (but again, I don't know which version of Windows) and that you want some component in your application (that you have deployed to OC4J) to write log messages to some file that is supposed to reside on another, UNIX machine (yet again, I don't know what UNIX version nor what type of machine) which is situated on the same local directory (i.e. LAN) as the Windows machine (that is running OC4J).
Assuming the above is correct, then you have two possibilities (in my opinion):
  • use a file URL which has the format: file://host ort/path/to/file
  • create (and use) a network mapping for the UNIX machine from the Windows machine. At my place of work we use "samba" software to do this. Unfortunately, I don't know much about it (I just use it).

  • However, your problem may also have to do with permissions. The Windows user (that "owns" the OC4J instance that is running) may not have permission to create files on the UNIX machine. But yet again, I can't help you with a more detailed answer since I didn't find enough information in your question to allow me to.
    And if the above is totally useless to you, then please excuse me.
    Hope it helps (anyway).
    Good Luck,
    Arch Tiwari

    Joined: Feb 07, 2003
    Posts: 6
    Hi Avi,
    Just to give you a little clarification --
    I have deployed my EAR file in the OC4J container on the Oracle 9iAS Server. This is installed on a UNIX sun solaris box.
    I need to access a file on the same Unix box but the directory is outside the OC4J home directory.
    Avi Abrami
    Ranch Hand

    Joined: Oct 11, 2000
    Posts: 1121

    Well, I see I was way off on that one :roll:
    Are you familiar with these Web sites/pages?
    Hope this helps you.
    Good Luck,
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Create a file at runtime
    Similar Threads
    Java code to Download a file from Server
    Unable to compile a package !!!
    Application Log Files
    log4j.properties in unix
    Log file not being created or appended to with log4j