Accessing a file in the local folder.

I want to create a File object using a file that is in the same folder as the JAR file. But I don't want to type in the entire path name. So how do I do this?
Here's an example of what I'm doing:
Instead of:
File file = new File("C:\\folder\\doc.txt");Just have:
File file = new File("doc.txt");except this doesn't work.

There's a relatively efficient way of finding the program's jar file (getClass().getProtectionDomain().getCodeSource().getLocation()), but it's probably not what you really want.
If the file is a read only resource then put it inside the .jar and use getClass().getResourceAsStream() to read it.
If it's to be written then how about sticking it in your home directory, or below it. (System.getProperty("user.home")). (+ \Application Data\myApplication ?)
Current directory isn't all that useful on Windows, it's more a shell script concept. But that's what a simple file name will give you.
You can run your program from a link, and set the current directory in that link (generate a link from java.exe or javaw.exe and add the parameters yourself).
Or you can ask the user where he wants the file the first time, and store the file path in a Preferences object.

Similar Messages

  • Help me to Access a File in the Local Network

    Hi everybody,
    I'm new to this field.
    I want to access a file in a machine on the local network from other machines.
    can anybody please give me a simple code for this.
    (actually I'm very little aware of this field)
    Thank You.

    Duminda_Dharmakeerthi wrote:
    Hi everybody,
    I'm new to this field.
    I want to access a file in a machine on the local network from other machines.
    can anybody please give me a simple code for this.This is not a code writing service.
    If you want to access a file on another machine, there are many different ways to do it. All of them require that the other machine be running some kind of service, and that your client machine knows what that service is and how to use it, and most also require your client to authenticate itself.
    You could mount a remote drive with Samba or NFS or Windows' file sharing.
    You could use FTP.
    You could use SCP.
    You could use HTTP.
    You could develop your own custom file sharing protocol.
    You could use some other option not mentioned here.

  • Any single file in my local folder of RoboHelp 10 which can be copied onto the application server?

    Pleasant Hello Pals, ( This is Vipin Nambiar from Bangalore)
    I am currently evaluating Adobe Robohelp 10 version for one of my technical architecture writing. Requesting help at the very earliest for the below-said big time hurdles.
    I have completed my technical writing for a in-house application system and have generated and viewing the primary layout (courtesy File -> View -> Primary Layout. ) as Contents, Index, Glossary and would like these to be hosted onto the server so that all the users of this application can access these Contents, Index, Glossary and act as a knowhow notes to use this application.
    Is there any single file in my local folder of Adobe RoboHelp 10 which can be copied onto the application server ?
    (My Adobe RoboHelp 10 local folder contains
    a.)Sub-folders called !Language!, !ScreenLayout!, !SkinSubFolder!, !SSL!
    b.)File Types called *.ALI File, *.APJ File, *.Bitmap image, *.BRS File, *.Cascading Style Sheet Document, *.CPD File, *.FPJ File, *.GIF image, *.GLO File, *.H File, *.HHC File, *.HHK File, *.HHP File, *.HTML Document, *.HTT File, *.JPEG image, *.JScript Script File, *.LDB File, *.PPF File, *.PSS File, *.Robohelp HTML Project File, *.SSL File, *.XML Document)
    Any help here will serve me in plentious

    First, your username cannot be changed and it is not a good idea to have email addresses visible on any forum, unless you enjoy reading spam.
    This question is covered in the online help. When you create an output it is generated to whatever folder you specify in the single source layout. Everything that is in that folder needs to go on the server.
    If the help is in !SSL! > WebHelp, then everything in that folder including sub-folders is what needs to go on the server.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • I am unable to access intranet on my MacBook Pro 13" with OS X mavericks. Is it possible to use files on the Local Area Network?

    I am unable to access intranet on my MacBook Pro 13" with OS X mavericks. Is it possible to use files on the Local Area Network? I use the files on the Local Area Network on my windows computer by typing in the I.P address in the library. Kindly guide me how i can use these files stored over the Local Area Network.

    I disabled GateKeeper's automatic blocking of unrecognised developers, and so I was able to install the driver.
    The Mobile Connect program is now installed, but the computer still does not recognise the modem.
    I also borrowed a USB hub from a friend and it didn't make a difference.

  • Accessing txt files in the App server from web application

    Hi All,
    We have a use case, where we need to access txt files from the ADF web application.
    We will display to the user the path of the file and whenever he/she clicks, it should be downloaded automatically to the users machine.
    Environments we need to develop: JDeveloper 10.1.3.4 and Oracle App Server 10.1.3.1
    And our server has credentials and only those who have access to the server can access the files.
    Point me or suggest me a good solution to this use case.
    Regards,
    Naga.

    Hi Joonas,
    i was able to download the files, thanks a lot for your guidance. i will mark your answer as correct.
    Can you let me know how to achieve the following usecase.
    1. there will be multiple text files in the server i.e., out of our web application context like in some folder
    2. And we need to give user a http link and if he clicks on the link that file should be downloaded automatically to his machine.
    and we are using oracle app server 10.1.3.4, please point me to some document or example.
    thank you.
    naga.

  • In Numbers 08 is it possible to add a link to a file on the local disc within a cell?

    In Numbers 08 is it possible to add a link to a file on the local disc within a cell?

    As it's a feature asked several times, maybe it will be available in the next version.
    I don't know features available in Excel.
    Sometimes ago I posted an AppleScript which may perhaps fit your needs.
    If you insert in a table pathnames of files stored in your HD, select the cell, trigger the script, open the file.
    Here is an updated version :
    --[SCRIPT open_a_file]
    Enregistrer le script en tant que Script : open_a_file.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Library:Scripts:Applications:Numb ers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner la cellule contenant le chemin d'accès
    Aller au menu Scripts , choisir Numbers puis choisir  “open_a_file”
    ouvre le fichier.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    --=====
    Save the script as a Script: open_a_file.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select the cell containing the pathname
    Go to the Scripts Menu, choose Numbers, then choose “open_a_file”
    open the file
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    Save this script as a … Script in the "Folder Actions Scripts" folder
    <startupVolume>:Library:Scripts:Folder Action Scripts:
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2010/02/02
    2011/04/28 - replaced the getSelParams handler by the get_SelParams one
    --=====
    on run
              set {dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
              tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
                        set maybe to value of cell rowNum1 of column colNum1
              end tell -- Numbers
              tell application "Finder" to open maybe
    end run
    --=====
    set { dName, sName, tName,  rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
    on get_SelParams()
              local d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2
              tell application "Numbers" to tell document 1
                        set d_Name to its name
                        set s_Name to ""
                        repeat with i from 1 to the count of sheets
                                  tell sheet i to set maybe to the count of (tables whose selection range is not missing value)
                                  if maybe is not 0 then
                                            set s_Name to name of sheet i
                                            exit repeat
                                  end if -- maybe is not 0
                        end repeat
                        if s_Name is "" then
                                  if my parleAnglais() then
                                            error "No sheet has a selected table embedding at least one selected cell !"
                                  else
                                            error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"
                                  end if
                        end if
                        tell sheet s_Name to tell (first table where selection range is not missing value)
                                  tell selection range
                                            set {top_left, bottom_right} to {name of first cell, name of last cell}
                                  end tell
                                  set t_Name to its name
                                  tell cell top_left to set {row_Num1, col_Num1} to {address of its row, address of its column}
                                  if top_left is bottom_right then
                                            set {row_Num2, col_Num2} to {row_Num1, col_Num1}
                                  else
                                            tell cell bottom_right to set {row_Num2, col_Num2} to {address of its row, address of its column}
                                  end if
                        end tell -- sheet…
                        return {d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2}
              end tell -- Numbers
    end get_SelParams
    --=====
    on decoupe(t, d)
              local l
              set AppleScript's text item delimiters to d
              set l to text items of t
              set AppleScript's text item delimiters to ""
              return l
    end decoupe
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Oops, I forgot that you are asking about Numbers '08 which hasn't AppleScript support.
    Yvan KOENIG (VALLAURIS, France) jeudi 28 avril 2011 16:26:39
    Please :
    Search for questions similar to your own before submitting them to the community

  • Unable to share files over the local network, OS X Lion

    About two weeks ago, my coworker and I realized that we were no longer able to share files over the local network. We have not made any changes to our preference settings. We are able to access FileMaker Pro databases files located on another computer in our office via the network, but we are unable to access any other files by trying to login to the computer remotely. We also have internet access. I am able to login to each of our work computers form home, but not from the office. I'm am not sure what has changed, but it is important that we have the ability to share files at work. Can you give me directions on how to fix our problem. Thanks!
    Debbie Roberts
    Univesrity of Texas at Austin

    I had this problem when I first setup my Mac. One thing I know is that File Sharing in System Preferences doesn't necessarily need to be on, because iTunes does all of the networking itself.
    I know that you've checked and checked again on the firewall, but what I did was turn the firewall on. In the list of ALLOW, there should be a line that is labeled iTunes Music Sharing. Check it. It was the magic link, and all of my iTunes libraries on the three computers in the house (two Windows, one my Mac) could "see" each other.
    Turning on the firewall might seem strange, but it worked for me.
    I hope this helps.
    MacBook Mac OS X (10.4.9)

  • Placing the file in the Dynamic folder

    Dear All,
    We are having the some requirment like.
    We developed one Adaptermodule to pick up the Excel sheet and reads and create one file for each sheet. These files are placing in one Target folder.
    Here we are developing the one more communication channel to pickup the file from this folder and trying to place the file in the particular folder based on the File name.
    Now my requirement is we need to place the file in the Target folder based on the File Name.
    For ex if the File name is INT0001.txt then we need to place this file in usr\sap\450\in\INT0001\  folder and
    if the file name is HIRING.txt then we need to place the file in usr\sap\450\in\HIRING\
    if the file name is INT009.txt then we need to place the file in usr\sap\450\in\INT009\
    Here we are not using any IR objects in this development.
    Please give any suggistions to solve this problem.
    Regards
    Goli Sridhar

    Hi,
      Try Variable Substitution method.Refer the link for use of Variable Substitution..
    [http://help.sap.com/saphelp_nw70/helpdata/EN/bc/bb79d6061007419a081e58cbeaaf28/content.htm]
    In file access parameter you should select create target directory.
    you should have read,write access for creating folder.
    Regards,
    Prakasu

  • Can somebody can tell me is CC for team can support to save the files in the local area without using the cloud ?

    Can somebody can tell me is CC for team can support to save the files in the local area without using the cloud ?

    The desktop applications are still installed on your computer, and the files are also saved on your computer.
    Optionally you can upload files with a browser to https://creative.adobe.com/files, or sync up files using the file sync that is part of the Creative Cloud desktop application. The online file storage is private to you, no one else can see it your files.
    If you do want to share your files there are two options:
    You can Collaborate, which is sharing a folder with another Adobe ID. Only the person you collaborate with can see the folder.
    You can use Send Link to send a publicly accessible url to a file or folder.

  • Getting Datapump Export Dump file to the local machine

    I apologize to everyone as this is a duplicate post.
    Re: Getting Datapump Export Dump file to the local machine
    My initial thread(started yesterday)was in 'Database General' and didn't get much response today. Where do i post questions on EXPORT/IMPORT utilities?
    Anyway, here is my problem:
    I want to take the export dump of itemrep schema in orcl database (in a remote machine). I have an Oracle server (10G Rel2) running in my local Windows machine. I have created a user john with necessary EXPORT/IMPORT privileges in my local db. Then i created a Directory object,ie a folder named datapump in my local hard drive and granted READ WRITE privileges to john.
    So john, who is a user in my local machine's oracle db is going to run the expdp utility.
    expdp john/jhendrix@my_local_db_alias SCHEMAS=itemrep directory=datapump logfile=itemrepexp.log
    The above command will fail because it will look for itemrep schema inside my local db, not the remote db where the itemprep is actually located. And you can't qualify the schemaname with its db in the SCHEMAS parameter (like SCHEMAS=itemrep@orcl).
    Can anyone provide me a solution for this?

    I think you can initiate the datapump exp utility from your client machine to export a schema in a remote database.But, Upon execution,oracle looks for the directory in the remote database and not on your local machine.
    You're inovoking expdp from a client (local DB) to export data from a remote DB.
    So, With this method, you can create the dumpfiles only on the Remote server and not on the local Machine.
    You can perform a direct import instead of export using the NETWORK_LINK option.
    Create a DBlink from your local and Remote DB and verify the connection.
    Then,Initiate the Impdp from Your local machine DB using the parameter network_link=<db_link of the Remote DB> to import the schema.
    The advantage of this option eliminates the Dumpfile creation at the Server side.
    There are no dumpfiles during the import process. the Data is imported directly to the target schema.

  • Where is the Local Folder in Mac Mail

    i have been banging my head against a wall trying to get my Local Folder mail from my current email handler into Mac Mail and for some reason I don't see this account in Mac Mail. I tried a search in the Help documentation and can't seem to find good info on this.
    can someone please help me figure out how I /move/ mail to the local folder and where i should see this folder?
    thanks!

    hey man. thanks.
    i have been having a bit of an epic battle but i am now realizing that these are now shown to me in Mac Mail after having File > Import > MBox these folders from my previous Mail handler (I /tried/ using postbox)...
    anyway, obviously now I can drag other mail to this Local Folder in Mac Mail since it is now there after having imported the info from elsewhere. not sure how one does this when Mail isn't showing a local folder but presumably there is a pulldown to move IMAP mail to Local.
    anyway, the big, big, big thing to know here is that you can transfer LOCAL FOLDER mail from a mail handler to Mac Mail by IMPORTING. I was trying to do this with Postbox via GMail and in addition to the upload speeds being very slow, there was not way to know if the operation was completed and it /seemed/ to crash out part way through. doing this in Postbox was like eating a Peanut Butter Sandwich (heavy peanut butter) while standing in quicksand...
    glad to be out of that trap.
    cheers!

  • Nothing shows up on my Desktop. I can put a file into the Desktop folder but it will not appear on the DTop. The HarDrive is not on the DTop either.

    Nothing appears on my Desktop. The Finder seems to work, so I can place a file into the DTop folder, but nothing appears on the DTop, not even the HarDrive.

    You can temporarily hide the crap on your desktop. Edit the CreateDesktop key in com.apple.finder:
    defaults write com.apple.finder CreateDesktop -bool false && killall Finder
    Then, to get my clutter back:
    defaults write com.apple.finder CreateDesktop -bool true && killall Finder

  • My ISP is telling me that iWeb is putting my files in the wrong folder?

    First time trying to publish a website! I am trying to upload my iWeb site files via FTP from a folder that was created by iWeb. My ISP is telling me that the files are being uploaded, but to a sun folder that is not the root directory. They have pushed me back to Apple to resolve. Any help would be apprecited.

    Hello,
    I not sure I understand your problem.
    Are you using the "Publish to a Folder…" command to publish into a site that you connected to with the Finder opening a FTP site?
    I assume the server in question is a Sun server.
    Until I get the answer to my question, let me point out a one thing that could be your problem.
    When iWeb publishes a site, it places into a folder (directory) named to match the name of the web site in iWeb. I referring to the first name in the left column. It defaults to "Site". But, iWeb does put an index.html file in the same folder, which should point web browsers directly into your web site.
    You can remove the contents of the folder and pull it up to the same level with any problem. So, everything in the "Site" folder would be placed at the same level as the "Site" folder.
    By the way, there is a reason for iWeb publishing into a subfolder, because can have multiple web sites in one file. Each site has its own folder.

  • Problem with my program looking for the settings file in the wrong folder

    I have been writing a simple FTP file uploader, what I want to do is be able to select the files I want to upload in windows explorer and then right click and click the menu item and it launches the program and passes the files paths that I have selected to it.
    So I use this in the windows registry "C:\Program Files\Java\jre1.6.0_03\bin\java.exe -jar D:\BenFTP\BenFTP.jar %1"
    It launches fine and has no problem finding the files I want to upload. The problem is that it tries to look for the settings file in the same folder that the file I am try to upload is in. Which it's not suppose to do since the settings file is in the same folder that the .jar is in.
    Edited by: ColNewman on Feb 5, 2008 6:55 PM

    So, you're looking for your settings file in your current working directory. There's no way to set the CWD in your registry entry (is there?) so that isn't a practical thing to do. Presumably you're using a File object or a FileReader or something? Can't do that.
    One alternative is to look for the settings file in the classpath. You can get a URL to a file in the classpath like this:URL settings = this.getClass().getResource("/settings.xml");Or you can get an InputStream to read the file by using the getResourceAsStream method. You would have to make sure that your executable jar file contained a Class-Path entry that specified the right directory, because the directory the jar is contained in isn't automatically in an executable jar's classpath.
    Another alternative is to ask the user where the settings file is supposed to be, and put an entry in the Preferences (java.util.prefs) to remember that location.

  • HT203200 Cannot delete the file from the itunes folder

    I cannont delete the file from the itunes folder because it tells me I need permission to do so.  I am the admin person for the laptop plus I have checked my permissions under the security tab in the files properties.  How do I delete this file to start again?  It downloaded 1.2GB of the file before the error message appeared, so its paid for and all but not looking like I'll get to watch it before the time runs out on the movie being available for me to watch. :-(

    Try deleting the file without iTunes running.
    When you next open iTunes it should then be marked as a missing file and you should be able to delete the entry from iTunes.
    Hope this works
    Regards,
    Colin R.

Maybe you are looking for

  • It's not showing the play or next song buttons on locks screen when the musics are played

    it's not showing the play or next song buttons on locks screen when the musics are played

  • Error "Can't find boot device by boot options" when boot from ISO via AMT

    Hello. When I try to boot from ISO CD via AMT I got an error message: "Can't find boot device by boot options" Settings are similar to what I made in HP 8100, 8200 etc - SOL/IDER/KVM, network access enabled Where could be a problem? Prod. name: HP Co

  • Pre defined, in built

    Hi,      I want to know all in-built functions,programs,reports,tables,fields, transaction codes,and all other standards which are in-built and there description,How can i?

  • Urgent: How access itab n variable in my calling program?

    I am working on report 'A' . I am calling Custom Report 'B' from my report 'A'. I can not edit report 'B'. I am calling report 'B' from report 'A' as below. submit B and return. I have to write code in my report 'A' on  Internal table and variable de

  • OSB & fn:replace

    Hi all, I've a proxy of type Any XML Service that publishes the contents to another system. The xml contents is: <msg_asset> <name_list> <name lang="automatic"> <normal>My Holding &#13;AG CHF (1111111)</normal> <short>My Hldg N</short> <long>My Holdi