Writing to file within another package

Hi all, I had a search in the forums, but I couldn't find what I was looking for.
I have what I consider to be good code organised into packages that make sense, but for some reason, I cannot programmatically save Files to where I want to.
If I create them manually, they read fine, (with
File xmlFile = new File(this.getClass().getClassLoader().
        getResource("data/records.xml").getFile());
SAXBuilder builder = new SAXBuilder();
Document xml = builder.build(xmlFile);).
So now I want to create this file programatically.
The code I have is
// Make a new file
File xmlFile = new File("data/" + p.getName() + "deck.xml");
xmlFile.createNewFile();But that gives (probably unsuprisingly)
java.io.IOException: The system cannot find the path specified
     at java.io.WinNTFileSystem.createFileExclusively(Native Method)
     at java.io.File.createNewFile(File.java:883)
     at gamepackage.PlayerDeck.updateDeck(PlayerDeck.java:99)When I create a file in the default package (probably frowned upon) with
// Try create file in default package
File xmlFile = new File(p.getName() + "deck.xml");
xmlFile.createNewFile();It works as expected (except my file is in the default package).
So, it must be a package problem. I have tried messing around with mkdir(), but that creates Files in directories called "data" rather than my existing package "data" (which confuses my little soul, because I thought packages were treated as directories (see JAR files etc)), and I have tried messing around with URIs and URLs, to little avail. Also, ClassLoaders such as
File xmlFile = new File(this.getClass().getClassLoader().
                  getResource("data/" + p.getName() + "deck.xml").getFile());wont work, because I need to create the file before I can call .getFile(); but I need the File to call createNewFile() on.
Please can you point me in the right direction? Many thanks in advance.

Hemmels wrote:
I've been playing CS and BF2142 and went for a jog, and we're into double figure views It's not a bad question, and you presented your problem well, it's just... well it isn't done this way. Packages are really intended to solve +this* problem. But the organization (and unique identifying) of source files problem.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Accesing file in another package

    I am using Netbeans 6.0 and I am currently accessing another text file in another package called "files" like so:
    br = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("\\files\\"+filename)));This works fine and finds the files when I run the code but it doesn't find the files when I build the jar file and run it separately.
    Any idea what could be happening?

    In a JAR, paths that start with a slash like:
    getResourceAsStream("/a/b/c/d.txt")Start at the "root" of the jar. For this to find the resource, verify that /a/b/c/d.txt is in the JAR.

  • How to unzip a zip file within another zip file

    I've got code that successfully processes a file within a zip file.
    But now the zip file can also contain other zip files. How can I
    process a zip nested within a zip without actually extracting the
    files? It looks like I need a ZipFile object to be able to take
    advantage of the zip classes for reading zip entries. But the
    ZipFile methods want as an argument an actual file, as opposed
    to some object in memory. I can read the 'inner' zip file into a
    ZipInputStream object, but then how do I make that available for
    processing as a ZipFile? I've searched all over and cannot find
    anything anywhere that talks about working with nested zip files.
    Does anyone have any sample code that does this? Thanks!

    I have successfully done it.
    You cannot have the code - it is proprietary.
    However here are a few pointers:
    o Use ZipStreams rather than ZipFile.
    o ZipStream is just a filter on a stream, so you can have a zipstream open, read a ZipEntry, then ask for a substream for the stuff up to the next ZipEntry. Put a second ZipStream on that substream.
    o As I recall you have to watch out that your inner ZipStream does not do a close. (Everything will get closed.) Instead, there is another ZipStream method that will close without closing all the underlying streams.
    Hope this helps.

  • How to load swf files within another SWF and still maintain actionscript

    Hi I was wondering how to embed an swf file inside another
    swf file, If i simply import it to the stage or the library it will
    become a symbol but the actionscript interactivity is lost, another
    question is can I have an actionscript 2 file play within an
    actionscript 3 file?
    The actionscript 2 code for embedding is something like this:
    don't mind the _mc titles
    this.cargame_mc.onRelease = function (){
    loadMovie ("Crusty Rusty's.swf", empty_mc)
    empty_mc._xscale=60;
    empty_mc._yscale=55;
    empty_mc._x=210;
    empty_mc._y=140;
    Please Help its for my uni portfolio, i want to use as2, but
    if i do i would lose the 3d possibility of as3, is there any way to
    export an as3 file and then embed in as2, using a program or
    anything? Thanks!I
    I would just like to say thanks in advance because everyone
    on here is so helpful!

    you can load an as2 file into an as3 file (using the loader
    class) and the actionscript will work in both.

  • Writing to file on another computer

    How can I write to a file on another computer using labview. My
    computers are networked together using Windows networking.
    thanks,
    stephen

    > How can I write to a file on another computer using labview. My
    > computers are networked together using Windows networking.
    >
    This is something that is a little different with each
    OS. You either need to mount the drive of the remote
    computer, or you use a string that includes the computer
    name, usually called a UNC name.
    Assuming you are on a PC, try using something like
    \\PCName\d:\directory\file.
    This is the path to the file, Open it, Write to it, and
    Close it. If you have problems, it may very well be a
    permissions problem. The remote computer will have to
    allow you to write to the disk. Typically this will
    involve going to the remote computer and publishing
    the drive or directory.
    Once you have permission and figure out what the path
    looks like, you
    just use the regular file I/O functions.
    This is the most straightforward approach and like I say,
    its done slightly different on different OSes. For
    computers that are more remote, or when you are changing
    OSes, you can use ftp client VIs or lots of other tools.
    Greg McKaskle

  • Compiling one java file within another java program

    Hi all,
    I want to compile one java file say one.java within a java program say second.java.. i simply have no idea as how to proceed ..pls help!!

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=dynamically+compile&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums
    Just to give you an idea.

  • Writing to files within EJBs

    I know the EJB spec says I'm not allowed to access any files from within an EJB.
    I recently discovered a developer on our team is using a FileWriter to do some
    custom outputting. I'm fairly sure that he's not allowed to do what he's doing,
    but to be honest I don't know why or how to get around it. When you really do
    need to print things out, what do you do?
    Also, the developer asked me a good question. What happens when an external jar
    called by an EJB needs to write out to a file too. Is that permitted? And again,
    if not, how do you get around it?
    Thanks,
    Andy

    its permitted in that it doesn't make the securitymanager mad, but its not
    really the correct way of stuff in an enterprise environment. ejb doens't
    like it because it cant figure out how to read/write a file in a clustered
    environment where different clusters have different filesystems underneath
    them. files cant be accessed via jndi. jdbc can. so they say 'go with jdbc',
    but everyone just pretends to not hear them. the nicest solution i've seen
    for writting stuff is the ejb -> log4j api -> single jms instance external
    to j2ee app server(s) -> file way cause you can look the jms server up via
    jndi and can guarantee one filesystem.
    -saad
    "Andrew Byala" <[email protected]> wrote in message
    news:[email protected]..
    >
    I know the EJB spec says I'm not allowed to access any files from withinan EJB.
    I recently discovered a developer on our team is using a FileWriter to dosome
    custom outputting. I'm fairly sure that he's not allowed to do what he'sdoing,
    but to be honest I don't know why or how to get around it. When youreally do
    need to print things out, what do you do?
    Also, the developer asked me a good question. What happens when anexternal jar
    called by an EJB needs to write out to a file too. Is that permitted?And again,
    if not, how do you get around it?
    Thanks,
    Andy

  • How to call swf file within another swf file using xml

    hii,
    I am facing some problem to call a swf file via xml when this xml file loaded it calls another swf file which includes a new xml file. now if i call this nested swf calling without xml it works but in case case of xml it is not showing the result. i m confused. how to nested xml file calling done in as2/as3. i need some logics. thanks in advance

    This is the AS3 forum and your posting involves AS2 code.  You should repost in the AS2 forum...
    http://forums.adobe.com/community/flash/flash_actionscript
    Aside from that, your problem might lie in the following lines...
    _root.createEmptyMovieClip("sub_container1", 1);
    loadMovie(sub_SWFPath[1].attributes.url, "sub_container1");
    You create the new movieclip, sub_container1,  in the _root, but you do not assign the loadMovie to load into that same movieclip (unless you have a _lockroot = true assigned in your sub-swf).  In any case, you should repost in the AS2 forum to pursue resolution.

  • Writing multiple files using UTL_File package

    Hi,
    I have an requirement where I need to read the flat file and based on the first 3 character in each line which will be compared with the FlagTable, I have to create and move data into different files.
    I'm using Oracle 11g in Windows xp platform.
    Example:
    Content of the FlatFile:
    ND1T00XNDCNON0080
    [email protected]
    XR1 0000000179CONVERSION
    PT1006 ON00014
    XR195010120391231P0012 19950101 0000000179CONVERSION
    ND2995010120391231a000000000000000000
    XR2 0000000416PP C941995010120391231PP0012 19950101
    GP206 0120391231a000
    GP2061231a00000000000000 1231a0000000000000
    FlagTable:
    Id     Flagtype Flag
    1     ND1     Y
    2     ND2     Y
    3     GP2     
    4     XR1     Y
    5     XR2     
    6     PT1     
    Possible output should be (duplicate files should not be created)
    BP_ND1.txt
    ND1T00XNDCNON0080
    ND151995010120391231a0000000000000000000000000000XNDCNON0080
    BP_ND2.txt
    [email protected]
    ND2995010120391231a000000000000000000
    BP_XR1.txt
    XR1 0000000179CONVERSION
    XR195010120391231P0012 19950101 0000000179CONVERSION
    BP.txt
    PT1006 ON00014
    XR2 0000000416PP C941995010120391231PP0012 19950101
    GP206 0120391231a000
    GP2061231a00000000000000 1231a0000000000000
    Please let me know, if more info is required.
    Regards,
    Lokesh

    How your task is related to Oracle?
    This better be done with Perl or VB or whatever, but not with using RDBMS.

  • Is it recommended to link an illustrator file within another illustrator file?

    Considering best practices for design reproduction... and that the linked file will contain a linked photoshop image.

    I believe once you link an image, wherever it goes goes the image, too.  Things get dicey when you move the image from where it was linked from, but if you have not moved the image and it shows it is still linked in the Links palette of the first Illustrator file ( which is placed into a new Illustrator document ), then the image remains linked.  So, to answer your question, no need to link again in the second file ( unless the link was somehow broken ).

  • Embedding an file within another

    Basically i want to embed a few files, for example pngs image between some xml tags in a new file. How can I store the file between the tags? I've tried to store a string based on a byte array for the file, however this doesn't seem to work and I think data is being lost when I convert it to a string... What would be the best way to embed the file?

    I might not completely be getting you but....
    Use a file stream (get the file's bytes) and just write them to the
    stream of your new saved file.
    http://java.sun.com/j2se/1.3/docs/api/java/io/FileInputStream.html
    DONT turn the file into a string and then write the string, lol.

  • How can we call a class file of one package for class file of another

    How can we call a class file of one package from class file of another package and both packages exist in a same folder

    How can we call a class file of one package from
    class file of another package and both packages exist
    in a same folder
    Luckily they don't so it's really not a problem after all.

  • Writing to files on windows

    Hi
    I have a jvm that will write some text to a file on a windows file system. There is some another process that will read it. This other process is beyond my control i.e. it wont be written by me and won't be java.
    How do i ensure that my jvm that writes to this file only when no other process is reading and also blocks on the write to prevent the other process trying to read when a write is in progress?
    I have read about FileChannel and FileLock and have tried writing a test app. My FileChannel tryLock call always seems to succeed, meaning that my write then goes ahead even when the other process is reading, which can cause this read to then fail.
    Any ideas? I know there are lots of hits for FileChannel and FileLock on this forum but nothing matching my requirements that i can see.
    appreciate any advice
    thanks

    Locks tend to be [advisory versus mandatory|http://java.sun.com/javase/6/docs/api/java/nio/channels/FileLock.html], so unless both processes are using locks, they don't work.
    One way to keep the reader from reading while you are writing is to write to a different fille in the same folder (say fileXXXXXXXX.tmp) then when you are done writing, rename it (say fileXXXXXXXX.txt).
    To keep from over-writing the file while another process is reading an earlier version.... hmmm.. include a unique timestamp in the name of the file?

  • A package that "patches" another package

    I'd like to make a PKGBUILD for usb-rndis-lite v0.11. Usb-rndis-lite contains files that should replace some files from 'kernel26' package. Is it right when one package replaces files from another package? If so, what is the right way to do that?
    The point is that USB RNDIS driver, included in current 2.6.26 kernel is either outdated or buggy, so sometimes it needs to be replaced by SynCE's usb-rndis-lite. Unfortunately that driver is a part of kernel26 package and cannot be separately removed.

    Mr.Cat wrote:Nothing would prevent me from doing this, but that would be the "wrong way", I suppose. And you've mentioned one of the reasons - possible problems with correct package removal. Another problem I see - is that when kernel26 is updated - my package's files would be owerwritten.
    Exactly. Pretty ugly solution, although possible. In the install script, you can specify an uninstall function, so theoretically you can backup the original driver on install, and restore on uninstall, with a check if it hasn't been updated meanwhile.
    UPD:
    bender02 wrote:There's a special directory where you can put your patched/updated version of a driver, and then modprobe/insmod would load that new version, when the driver is requested.
    Thanks, worked for me.
    UPD:
    I've submitted a PKGBUILD for rndis-usb-lite (v0.11) to unsupported: http://aur.archlinux.org/packages.php?ID=20336.
    I'm glad it worked.

  • Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick?

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

Maybe you are looking for

  • Having issues with getting SQL Server Express to start services and run.

    Good afternoon everyone, I have been working on a 2012 R2 server getting ready to move databases to new hardware.  I had SQL Server Express 2008 R2 running on this server with no issues.  I was handed another software package that ran SQL Express 201

  • Wireless internet does not work on EA6500 saying limited or no connectivity (With Solution)

    I've had this router for about two weeks and all of a sudden two laptops in the house were no longer able to connect to the internet. They would take a really long time connecting to the router but you could nowhere on the internet with the message s

  • INVOIC idoc

    Hi all,             i am using INVOIC02 to post non PO invoice into SAP .my problem is in line item level want to pass long text through IDOC. when i am passing values in E1EDPT1 and E1EDPT2 ..the respective text is inserting into text column but i w

  • Print off call history

    Hi guys, I am a newbie so hope someone can help me out here. My wife is Chinese and we are applying for UK visa to be together. One of the requirements is to prove our contact history. What would be the best way to print out or get a official copy of

  • Image made on CS5 W7 64 computer won't print with CS5 XP computer – Epson 9880

    I have 2 computers with CS5. One is new, with Windows 7 64. The other is XP. My printer is Epson 9880, which is connected to the XP computer. The computers are networked, but I only print from the XP computer. On my XP computer, I have opened a file