Accessing files in a different package

Hello,
Is there a way to access files outside the current package in Java?
I have a situation where I need to get the URL object out of a file, but it requires the file to be in the current directory of the class, is there a way to access file based on package name?
URL url = getClass().getResource(filename);
Your help would be appreciated as always.
Thanks.
--Raj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

This doesn't sound like a package issue as much as it is a classpath issue. If you put an arbitrary directory on your classpath, a call to getResource() will search that directory for the file.

Similar Messages

  • Accessing file sharing on different platforms

    Hello
    Recently I purchased a Mac mini server edition, for multiple reasons, the primary being file sharing.  For multiple reason I need terabytes of storage space to share over the Internet.  Completely unaware of how to run a server, I went ahead and bought one.
    For the most part, everything came together smoothly.  There's a lot to learn but I'm getting the hang of it.  But one thing I can NOT figure out is how to access files that are being shared on an iPhone/iPad or a windows computer (I'm other terms how to connect to the server).  I have spent countless hours reading every Internet article there is and no luck.
    I have both WebDav and SMB turned on, but when I try to access it from a mobile device i get "Forbidden you don't have permission to access / on this server
    Apache/2.2.20............... Port 443"
    And no matter what site I "run" on a windows, it says there is nothing.
    If anybody could help me out with these, it would be awesome!!
    Thanks
    Ben

    It seems this is not possible.
    have requested a change to a future version, but not holding my breath.

  • Compiling multiple java files present in different packages simultaneously

    Hi,
    I have multiple java files which are present in different folders.
    In some cases, files are importing classes from other packages i.e. some kind of inter-dependency
    How do I compile these java files simultaneously?
    Any help would be highly appreciated.

    Pawan_Anand wrote:
    Hi,
    I have multiple java files which are present in different folders.
    In some cases, files are importing classes from other packages i.e. some kind of inter-dependency
    How do I compile these java files simultaneously?
    Is it circular?
    Thus the dependency is A => B => C => A?

  • Best way to access files at two different locations

    Hey Guys,
    I am in need of some help. We currently have about six macs in our prepress department all accsessing 1 mac mini with three external drives that store all our files. We also work out of those drives, not on our local machines.
    So far this has worked out well for us. However, in the next few weeks we will be opening a new shop about 20 miles away, that will need access to all these same exact files. We are not sure of what the best way to do this is.
    Currently the mac mini we are on does not have osx server just osx. Also we have about 4-5 TB of customer files, and any given file that we are working on or would need access to could be up to 2 GB's.
    We are open to all and any ideas. Obviously the cheaper the better, but please give me any and all ideas so that we can evaluate every option and decide what is best for our company.
    We know that our current state of using external drives on a mac mini in not a realistic solution for ever as eventually our drives will fill up and I think we are out of usb ports to add new ones on.
    Also this cannot be a one time type of fix as once we get this new location set up and established, we plan to replicate it and open up a couple more in the comming years. Also seeing as we already have 4-5 TB of data we need something that is future proof so that as we continue to expand and grow we end up needing a new solution in 5 years.
    Thank you for any and all help you can provided.
    -ey3ball

    @rccharles// Do you know of any software that would duplicate or mirror a sever?
    I do not have personal experience beyond dropbox.
    sync
    SyncTwoFolders simply synchronizes two folders. might be more for client.
    https://www.macupdate.com/app/mac/22644/synctwofolders/
    Unix rsync
      whether it copies mac metadata may depend on what version of X you have.  May depend transfer app you use AFS, NFS, Samba.
    dropbox
    Well, if you want with Dropbox, you could use Dropbox to do the syncing. I think this is the way to go because you would get offsite backup. Not sure i'd try to sync the two servers. Duplicate each server to Dropbox.  Provide read-only access to the other site.
    You could experiment around with two computers and a dropbox account.  See how it works for you.  It's free upto two gigs.
    versioning
    dropbox has versioning build in.  using sometype of version system while necessary was viewed as a PITA by most programmers.  The best system would be an automated on where you didn't have to do anything beyond what you were doing before.  Timemachine, etc.
    dropbox
    also would we just talk to our internet provider about a private fiber channel?
    I think Linc Davis has the idea.
    Router-to-router VPN.
    I was putting the concept out there.

  • Corrupted user account - access files from a different user?

    I am writing with a problem that I've had for about a week now, and which I have been working with an Apple tech support person to resolve, but I figured I would give this forum a shot, as well.
    Last Sunday, my Finder suddenly died on me - I think it was the result of a corrupt file. I first noticed it when I would mouse over my desktop and get a perpetual beachball. I couldn't open a Finder window (or use any applications that rely on accessing my files - iPhoto, iTunes, etc.; the only application that seems to work fine is my internet browser), and when I restarted my computer, I got the same issue when it was back on. I called Apple support and have been working with a senior support rep. We did an archive and install, recreating my old user account named exactly as it had been before. Once I was logged back in, though, I again got the beachball on my desktop. The other admin accounts on the computer do not have the Finder beachball problem, so it is linked specifically to my account. Paul (my tech support friend) recommended that I buy an external hard drive, and if we can't figure out a solution short of backing up my files and erasing my hard drive, we'll do that.
    My question is as follows: will I even be able to access the files on my account from another account if the finder in my account isn't working? I really only want to back up my work files, music, and photos. I can get everything else back. There are now two (or maybe three) admin accounts on my computer - can these accounts access each other's files?
    I appreciate any answers to my question (or any advice you might have for how else I could resolve this situation).
    Thanks!
    Message was edited by: EMV123

    Assuming the problem account has short user name "foo", and one of the other working accounts has short user name "bar", try this:
    1) Log out of the foo account.
    1) Log in as bar.
    2) Open Terminal and enter this:
    su foo (press return, enter foo's password when prompted)
    rm ~/Library/Preferences/com.apple.Finder.plist
    exit
    See if foo's Finder works now.

  • Accessing files across clusters

    I wasn't sure if this would go here or in the Off-Topic, so I flipped a coin.
    Background: My workplace has an EVAL environment and a PROD environment which are basically off-limits to developers. These are unix boxes which have weblogic servers in a cluster. Logical or Physical, I am not sure. We developers of applications don't even have access to the logs etc. This is a major pain in the ass since the snotty-assed unix admins require a "upper level clearance" before they can hand us log files. Jeez !
    Possible Solution: An idea that me and a fellow developer has suggested to our bosses, is to have a link in all of our apps called "View Logs" which will be accessible only to developers of the said app. Our bosses have told us that if we can do something like this, they would push the required buttons to get us access to the log files of individual apps so that we can display it in the app itself or allow them to download it.
    The solution seems easy enough to implement on a single instance of a server. You get access to the logs and just display the last 200 odd lines on a html page or give them the option of downloading the entire file. However, because our servers are in a cluster, if any error has occurred on server2, and if the developer logs on server1, he will never be able to see the same log file. And because of sticky sessions, refresh of the page is not going to connect him to the other server either.
    So I wanted to ask if anyone had any experience with something like this. How can one access files across a different server on the same cluster? I will have to check any solutions that you guys provide, to make sure if it passes company security policies etc.etc. So any other solutions (totally unrelated to the above) are welcome too.
    Thanks
    Last edited by Inxsible (2010-08-05 15:07:46)

    Wow,  cool. There is no knowledge about cluster on my side. However, speaking of several hosts connected in one network, yes.
    AFAIK, several nodes in the cluster would be accessible via a unique NIC and thus IP. Maybe you can  setup the solution you mentioned on every node / virtual node? You can probably have a script solution to pull from every node and grep for the interessting lines.

  • Accessing a dll from classes in different packages

    Hello java community,
    I am new to Java and especially the jni so your help is greatly appreciated.
    I am having trouble accessing a Windows native dll from classes in different packages. I placed the .dll in my ClassPath. I am able to loadLibrary successfully from class X in my 'common' package. However, when I try to access the same .dll from another class Y in package 'notsocommon'. I get an unsatisfied link error. I changed the X.h file to include common in the function definition (eg. Java_common_X_functionName) and I did the same to the Y.h file (Java_notsocommon_Y_functionName). I am able to work with the dll from the X class but not the Y class. I don't know what I am doing wrong. I am very new to Java, so any help is appreciated.
    Thank you.

    I apologize to everyone for posting this. I figured out my mistake, it was in the dll and not in the java. Also using
    javah -jni notsocommon.Y
    creates the correct header file.

  • Access file reside in the solution/package files on azure

    Hi All,
    I have one file in my solution and it will be uploaded along with package file. now one of the task is to validate file uploaded by end-user with file reside in solution. i am keeping uploaded file into the block blob.
    how i can access file reside in solution on cloud ? should i have to kept file in blob or do we have other better option ?
    BR,
    Jonyy

    Hi,
    As I know you can use the Get Package API from Windows Azure Service Management REST API to retrieve files. I think storing files in blob is still a good way:
    http://msdn.microsoft.com/en-us/library/windowsazure/jj154121.aspx
    Thanks,
    QinDian Tang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Files with same name in different packages

    I have a file with the same name defined in two different packages.
    When I generate the javadoc, I get an error saying that
    Class com.eg.toolkit.Email already defined in com.eg.common.Email.java
    Does javadoc expect all files to be of different names acroos packages?
    Thanks
    Chintu

    You can use the same class name in different packages.
    The Java API does that (java.awt.List, java.util.List).
    This is odd. What version of javadoc are you using,
    and what command are you passing in, with what classpath setting?
    -Doug Kramer
    javadoc team

  • Create file object from xml file in different package

    I have my java class which is in a package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The path of xml file shld be independent of my OS path... it can only lookup the package path..
    I will really appreciate it if someone can throw some input as to how to resolve this issue..
    Thank you

    I have my java class which is in a
    package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The
    path of xml file shld be independent of my OS path...
    it can only lookup the package path..
    I will really appreciate it if someone can throw some
    input as to how to resolve this issue..
    Thank you
    InputStream inputStream = getClass().getResourceAsStream("xml/formats.xml");
    /* OR */
    URL url = getClass().getResource("xml/formats.xml");hth

  • How can I access files that I moved from an older MacBook Pro to a newer one via Firewire and Migration assistant.  The files show up on the new MacBook but cannot be opened.  Thanks!

    How can I access files that I moved from an older MacBook Pro to a newer one via Firewire and Migration assistant?  The files show up on the new MacBook but cannot be opened.  Thanks!

    Get info then check permissions then add your curent user name (it was probably different on old Mac) and give your username full read/write permissions.

  • Office 2010 & 2007 - Excel and Access File Locking Out On the Network With Multiple Users

    This is also posted in the Office 2010 - IT Pro General Discussions, but was suggested to repost here, since a definitive answer was not found.
    Hi,
    An issue that's happening is that Excel and Access files are locking on the network. We're currently using Office 2007 and 2010.
    Here are some different scenarios that are happening:
    When opening the file it is locked out by “User X” which is the person that has the file locked out and no one else can open the file.
    When opening the file it is locked out by “User Y” which is NOT the actual person, but is locked out by “User X” and no one else can access the file.
    When opening the file  it is locked out by “…another user” which is generic and no one else can access the file.
    The two more common events are incident 1 and 2 with 3 happening the less common.
    This message will continue until the sessions are closed through computer management on the file server.
    The file server is running Windows Server 2003.
    This does happen on both Windows XP and Windows 7 clients.
    This does happen for users using Office 2007 and Office 2010.
    There are two sets of Office 2010 Users when it comes to patches. Everyone has the most current patches with Office 2010 SP2 while anyone that has Microsoft Project 2010 is using all the current update before Office 2010 SP2.
    All users that are using Office 2007 have all the current patches and service packs.
    Another variable is that we have users that will leave a file open on the network for 3+ days and after a while it will lock the file out.
    Also we have Shadow Copy that runs daily on the system which I'm not for sure if that impacts anything if a file is opening during that time.
    Any ideas on how to mitigate the lock out issues would be appreciated.
    Thanks,
    Binary Process
    Edit November 12, 2013: This issue can occur if and if not another person actually has the file open. If the person doesn't have the file open then there is a hung connection which needs to be disconnected by going to the Computer Management of the File
    server.

    Hi Binary,
    I know that the description of the hotfix does not relate to the issue. The purpose is to install it for upgrading SMB related file.
    A similar issue I encountered before:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b7fcc59b-52d9-4a02-863a-1a529bcb8cb1/temp-doc-etc-files-dont-close-after-a-file-closes-this-causes-locked-files?forum=winserverfiles
    It is resolved by upgrading SMB files so maybe it will help on your case.
    Another hotfix which may related:
    http://support.microsoft.com/kb/983458
    If you have any feedback on our support, please send to [email protected]

  • Modify Record Number in a Random Access File

    Hi Does anyone know if I can modify the record number in the random access file hardware.dat for each hardware record each time and update it in hardware.dat to display it? Also why does it say "Record does not exist" if I modify the record number for a hardware and try to update it but could not find that record?
    Here is the code below:
    // Exercise 14.11: HardwareRecord.java
    package org.egan; // packaged for reuse
    public class HardwareRecord
      private int recordNumber;
      private String toolName;
      private int quantity;
      private double cost;
      // no-argument constructor calls other constructor with default values
      public HardwareRecord()
        this(0,"",0,0.0); // call four-argument constructor
      } // end no-argument HardwareRecord constructor
      // initialize a record
      public HardwareRecord(int number, String tool, int amount, double price)
        setRecordNumber(number);
        setToolName(tool);
        setQuantity(amount);
        setCost(price);
      } // end four-argument HardwareRecord constructor
      // set record number
      public void setRecordNumber(int number)
        recordNumber = number;
      } // end method setRecordNumber
      // get record number
      public int getRecordNumber()
        return recordNumber;
      } // end method getRecordNumber
      // set tool name
      public void setToolName(String tool)
        toolName = tool;
      } // end method setToolName
      // get tool name
      public String getToolName()
        return toolName;
      } // end method getToolName
      // set quantity
      public void setQuantity(int amount)
        quantity = amount;
      } // end method setQuantity
      // get quantity
      public int getQuantity()
        return quantity;
      } // end method getQuantity
      // set cost
      public void setCost(double price)
        cost = price;
      } // end method setCost
      // get cost
      public double getCost()
        return cost;
      } // end method getCost
    } // end class HardwareRecord-------------------------------------------------------------------------------------------------
    // Exercise 14.11: RandomAccessHardwareRecord.java
    // Subclass of HardwareRecord for random-access file programs.
    package org.egan; // package for reuse
    import java.io.RandomAccessFile;
    import java.io.IOException;
    public class RandomAccessHardwareRecord extends HardwareRecord
      public static final int SIZE = 46;
      // no-argument constructor calls other constructor with default values
      public RandomAccessHardwareRecord()
        this(0,"",0,0.0);
      } // end no-argument RandomAccessHardwareRecord constructor
      // initialize a RandomAccessHardwareRecord
      public RandomAccessHardwareRecord(int number, String tool, int amount, double price)
        super(number,tool,amount,price);
      } // end four-argument RandomAccessHardwareRecord constructor
      // read a record from a specified RandomAccessFile
      public void read(RandomAccessFile file) throws IOException
        setRecordNumber(file.readInt());
        setToolName(readName(file));
        setQuantity(file.readInt());
        setCost(file.readDouble());
      } // end method read
      // ensure that name is proper length
      private String readName(RandomAccessFile file) throws IOException
        char name[] = new char[15], temp;
        for(int count = 0; count < name.length; count++)
          temp = file.readChar();
          name[count] = temp;
        } // end for
        return new String(name).replace('\0',' ');
      } // end method readName
      // write a record to specified RandomAccessFile
      public void write(RandomAccessFile file) throws IOException
        file.writeInt(getRecordNumber());
        writeName(file, getToolName());
        file.writeInt(getQuantity());
        file.writeDouble(getCost());
      } // end method write
      // write a name to file; maximum of 15 characters
      private void writeName(RandomAccessFile file, String name) throws IOException
        StringBuffer buffer = null;
        if (name != null)
          buffer = new StringBuffer(name);
        else
          buffer = new StringBuffer(15);
        buffer.setLength(15);
        file.writeChars(buffer.toString());
      } // end method writeName
    } // end RandomAccessHardwareRecord-------------------------------------------------------------------------------------------------
    // Exercise 14.11: CreateRandomFile.java
    // creates random-access file by writing 100 empty records to disk.
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import org.egan.RandomAccessHardwareRecord;
    public class CreateRandomFile
      private static final int NUMBER_RECORDS = 100;
      // enable user to select file to open
      public void createFile()
        RandomAccessFile file = null;
        try  // open file for reading and writing
          file = new RandomAccessFile("hardware.dat","rw");
          RandomAccessHardwareRecord blankRecord = new RandomAccessHardwareRecord();
          // write 100 blank records
          for (int count = 0; count < NUMBER_RECORDS; count++)
            blankRecord.write(file);
          // display message that file was created
          System.out.println("Created file hardware.dat.");
          System.exit(0);  // terminate program
        } // end try
        catch (IOException ioException)
          System.err.println("Error processing file.");
          System.exit(1);
        } // end catch
        finally
          try
            if (file != null)
              file.close();  // close file
          } // end try
          catch (IOException ioException)
            System.err.println("Error closing file.");
            System.exit(1);
          } // end catch
        } // end finally
      } // end method createFile
    } // end class CreateRandomFile-------------------------------------------------------------------------------------------------
    // Exercise 14.11: CreateRandomFileTest.java
    // Testing class CreateRandomFile
    public class CreateRandomFileTest
       // main method begins program execution
       public static void main( String args[] )
         CreateRandomFile application = new CreateRandomFile();
         application.createFile();
       } // end main
    } // end class CreateRandomFileTest-------------------------------------------------------------------------------------------------
    // Exercise 14.11: MenuOption.java
    // Defines an enum type for the hardware credit inquiry program's options.
    public enum MenuOption
      // declare contents of enum type
      PRINT(1),
      UPDATE(2),
      NEW(3),
      DELETE(4),
      END(5);
      private final int value; // current menu option
      MenuOption(int valueOption)
        value = valueOption;
      } // end MenuOptions enum constructor
      public int getValue()
        return value;
      } // end method getValue
    } // end enum MenuOption-------------------------------------------------------------------------------------------------
    // Exercise 14.11: FileEditor.java
    // This class declares methods that manipulate hardware account records
    // in a random access file.
    import java.io.EOFException;
    import java.io.File;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.util.Scanner;
    import org.egan.RandomAccessHardwareRecord;
    public class FileEditor
      RandomAccessFile file; // reference to the file
      Scanner input = new Scanner(System.in);
      // open the file
      public FileEditor(String fileName) throws IOException
        file = new RandomAccessFile(fileName, "rw");
      } // end FileEditor constructor
      // close the file
      public void closeFile() throws IOException
        if (file != null)
          file.close();
      } // end method closeFile
      // get a record from the file
      public RandomAccessHardwareRecord getRecord(int recordNumber)
         throws IllegalArgumentException, NumberFormatException, IOException
        RandomAccessHardwareRecord record = new RandomAccessHardwareRecord();
        if (recordNumber < 1 || recordNumber > 100)
          throw new IllegalArgumentException("Out of range");
        // seek appropriate record in a file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        record.read(file);
        return record;
      } // end method getRecord
      // update record tool name in file
      public void updateRecordToolName(int recordNumber, String newToolName)
         throws IllegalArgumentException, IOException
        RandomAccessHardwareRecord record = getRecord(recordNumber);
        if (record.getRecordNumber() == 0)
          throw new IllegalArgumentException("Record does not exist");
        // seek appropriate record in file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        record.setToolName(newToolName);
        record = new RandomAccessHardwareRecord(
           record.getRecordNumber(), record.getToolName(), record.getQuantity(), record.getCost());
        record.write(file); // write updated record to file
      } // end method updateRecordToolName
      // update record in file
      public void updateRecordQuantity(int recordNumber, int newQuantity)
         throws IllegalArgumentException, IOException
        RandomAccessHardwareRecord record = getRecord(recordNumber);
        if (record.getRecordNumber() == 0)
          throw new IllegalArgumentException("Record does not exist");
        // seek appropriate record in file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        record.setQuantity(newQuantity);
        record = new RandomAccessHardwareRecord(
           record.getRecordNumber(), record.getToolName(), record.getQuantity(), record.getCost());
        record.write(file); // write updated record to file
      } // end method updateRecordQuantity
      // update record in file
      public void updateRecordCost(int recordNumber, double newCost)
         throws IllegalArgumentException, IOException
        RandomAccessHardwareRecord record = getRecord(recordNumber);
        if (record.getRecordNumber() == 0)
          throw new IllegalArgumentException("Record does not exist");
        // seek appropriate record in file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        record.setCost(newCost);
        record = new RandomAccessHardwareRecord(
           record.getRecordNumber(), record.getToolName(), record.getQuantity(), record.getCost());
        record.write(file); // write updated record to file
      } // end method updateRecordCost
      // add record to file
      public void newRecord(int recordNumber, String toolName, int quantity, double cost)
         throws IllegalArgumentException, IOException
        RandomAccessHardwareRecord record = getRecord(recordNumber);
        if (record.getRecordNumber() != 0)
          throw new IllegalArgumentException("Record already exists");
        // seek appropriate record in file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        record = new RandomAccessHardwareRecord(recordNumber, toolName, quantity, cost);
        record.write(file); // write record to file
      } // end method newRecord
      // delete record from file
      public void deleteRecord(int recordNumber) throws IllegalArgumentException, IOException
        RandomAccessHardwareRecord record = getRecord(recordNumber);
        if (record.getRecordNumber() == 0)
          throw new IllegalArgumentException("Account does not exist");
        // seek appropriate record in file
        file.seek((recordNumber - 1) * RandomAccessHardwareRecord.SIZE);
        // create a blank record to write to the file
        record = new RandomAccessHardwareRecord();
        record.write(file);
      } // end method deleteRecord
      // read and display records
      public void readRecords()
        RandomAccessHardwareRecord record = new RandomAccessHardwareRecord();
        System.out.printf("%-10s%-15s%-15s%10s\n","Record","Tool Name","Quantity","Cost");
        try  // read a record and display
          file.seek(0);
          while (true)
            do
              record.read(file);
            while (record.getRecordNumber() == 0);
            // display record contents
            System.out.printf("%-10d%-15s%-15d%10.2f\n",record.getRecordNumber(),
               record.getToolName(), record.getQuantity(), record.getCost());
          } // end while
        } // end try
        catch (EOFException eofException)  // close file
          return;  // end of file was reached
        } // end catch
        catch (IOException ioException)
          System.err.println("Error reading file.");
          System.exit(1);
        } // end catch
      } // end method readRecords
    } // end class FileEditor-------------------------------------------------------------------------------------------------
    // Exercise 14.11: TransactionProcessor.java
    // A transaction processing program using random-access files.
    import java.io.IOException;
    import java.util.NoSuchElementException;
    import java.util.Scanner;
    import org.egan.RandomAccessHardwareRecord;
    public class TransactionProcessor
      private FileEditor dataFile;
      private RandomAccessHardwareRecord record;
      private MenuOption choices[] = {MenuOption.PRINT, MenuOption.UPDATE, MenuOption.NEW,
              MenuOption.DELETE, MenuOption.END};
      private Scanner input = new Scanner(System.in);
      // get the file name and open the file
      private boolean openFile()
        try // attempt to open file
          // call the helper method to open the file
          dataFile = new FileEditor("hardware.dat");
        } // end try
        catch (IOException ioException)
          System.err.println("Error opening file.");
          return false;
        } // end catch
        return true;
      } // end method openFile
      // close file and terminate application
      private void closeFile()
        try // close file
          dataFile.closeFile();
        } // end try
        catch (IOException ioException)
          System.err.println("Error closing file.");
          System.exit(1);
        } // end catch
      } // end method closeFile
      // create, update or delete the record
      private void performAction(MenuOption action)
        int recordNumber = 0;  // record number of record
        String toolName;       // tool name of the hardware instrument
        int quantity;          // total amount of items
        double cost;           // hareware tool price
        int choice;            // choose an update option   
        int newRecordNumber;   // the updated record number
        String newToolName;    // the updated tool name
        int newQuantity;       // the updated quantity
        double newCost;        // the updated cost
        try // attempt to manipulate files based on option selected
          switch(action) // switch based on option selected
            case PRINT:
              System.out.println();
              dataFile.readRecords();
              break;
            case NEW:
              System.out.printf("\n%s%s\n%s\n%s","Enter record number,",
                "tool name, quantity, and cost.","(Record number must be 1 - 100)","? ");
              recordNumber = input.nextInt();  // read record number       
              toolName = input.next();         // read tool name
              quantity = input.nextInt();      // read quantity
              cost = input.nextDouble();       // read cost
              dataFile.newRecord(recordNumber, toolName, quantity, cost); // create new record
              break;
            case UPDATE:
              System.out.print("\nEnter record number to update (1 - 100): ");
              recordNumber = input.nextInt();
              record = dataFile.getRecord(recordNumber);
              if (record.getRecordNumber() == 0)
                System.out.println("Record does not exist.");
              else
                // display record contents
                System.out.printf("%-10d%-12s%-12d%10.2f\n\n", record.getRecordNumber(),
                   record.getToolName(), record.getQuantity(), record.getCost());
                System.out.printf("%s%s","\nEnter 1 to update tool name, ",
                  "2 to update quantity, or 3 to update cost : ");
                choice = input.nextInt();
                if (choice == 1)
                  System.out.print("Enter new record tool name : ");
                  newToolName = input.next();
                  dataFile.updateRecordToolName(recordNumber,newToolName); // update record
                                                                           // tool name            
                  // retrieve updated record
                  record = dataFile.getRecord(recordNumber);
                  // display updated record
                  System.out.printf("%-10d%-12s%-12d%10.2f\n", record.getRecordNumber(),
                     record.getToolName(), record.getQuantity(), record.getCost());
                else if (choice == 2)
                  System.out.print("Enter new record quantity : ");
                  newQuantity = input.nextInt();
                  dataFile.updateRecordQuantity(recordNumber,newQuantity); // update record
                                                                           // quantity             
                  // retrieve updated record
                  record = dataFile.getRecord(recordNumber);
                  // display updated record
                  System.out.printf("%-10d%-12s%-12d%10.2f\n", record.getRecordNumber(),
                     record.getToolName(), record.getQuantity(), record.getCost());
                else if (choice == 3)
                  System.out.print("Enter new record cost : ");
                  newCost = input.nextDouble();
                  dataFile.updateRecordCost(recordNumber,newCost); // update record cost            
                  // retrieve updated record
                  record = dataFile.getRecord(recordNumber);
                  // display updated record
                  System.out.printf("%-10d%-12s%-12d%10.2f\n", record.getRecordNumber(),
                     record.getToolName(), record.getQuantity(), record.getCost());
              } // end else     
              break;
            case DELETE:
              System.out.print("\nEnter an account to delete ( 1 - 100): ");
              recordNumber = input.nextInt();
              dataFile.deleteRecord(recordNumber);  // delete record
              break;
            default:
              System.out.println("Invalid action.");
              break;
          } // end switch
        } // end try
        catch (NumberFormatException format)
          System.err.println("Bad input.");
        } // end catch
        catch (IllegalArgumentException badRecord)
          System.err.println(badRecord.getMessage());
        } // end catch
        catch (IOException ioException)
          System.err.println("Error writing to the file.");
        } // end catch
        catch (NoSuchElementException elementException)
          System.err.println("Invalid input. Please try again.");
          input.nextLine();
        } // end catch
      } // end method performAction
      // enable user to input menu choice
      private MenuOption enterChoice()
        int menuChoice = 1;
        // display available options
        System.out.printf("\n%s\n%s\n%s\n%s\n%s\n%s","Enter your choice",
         "1 - List hardware records", "2 - Update a hardware record",
         "3 - Add a new hardware record", "4 - Delete a hardware record", "5 - End program\n?");
        try
          menuChoice = input.nextInt();
        catch (NoSuchElementException elementException)
          System.err.println("Invalid input.");
          System.exit(1);
        } // end catch
        return choices[menuChoice - 1];  // return choice from user
      } // end enterChoice
      public void processRequests()
        openFile();
        // get user's request
        MenuOption choice = enterChoice();
        while (choice != MenuOption.END)
          performAction(choice);
          choice = enterChoice();
        } // end while
        closeFile();
      } // end method processRequests
    } // end class TransactionProcessor-------------------------------------------------------------------------------------------------
    // Exercise 14.11: TransactionProcessorTest.java
    // Testing the transaction processor.
    public class TransactionProcessorTest
      public static void main(String args[])
         TransactionProcessor application = new TransactionProcessor();
         application.processRequests();
      } // end main
    } // end class TransactionProcessorTest-------------------------------------------------------------------------------------------------
    Below is the sample data to be entered into the random input file hardware.dat :
    Record                     Tool                        Quantity                Cost
    Number                   Name                
       3                      Sander                    18                         35.99
      19                      Hammer                128                      10.00
      26                      Jigsaw                   16                        14.25
      39                      Mower                    10                        79.50
      56                      Saw                        8                          89.99
      76                      Screwdriver            236                      4.99
      81                      Sledgehammer       32                        19.75
      88                      Wrench                      65                        6.48Message was edited by:
    egan128
    Message was edited by:
    egan128
    Message was edited by:
    egan128

    Hi Does anyone know if I can modify the record number
    in the random access file hardware.dat for each
    hardware record each time and update it in
    hardware.dat to display it?If the "record number" is data that is stored in the file, then you can modify it. More precisely: it is possible to modify it.
    The rest of the question had too many incompatible verbs for me to understand it.
    Also why does it say
    "Record does not exist" if I modify the record number
    for a hardware and try to update it but could not
    find that record?"Record does not exist" is a fairly reasonable error message for the situation where a program looks for a record but cannot find it. Are you asking why that particular lump of code actually does that?
    (One thousand lines of code removed)

  • Save the uploaded file in a different name ?

    Has anyone used the com.oreilly.MultipartRequest Class
    which is used to upload a file to a directory.I am able to that
    fine.I now need a way to save the uploaded file to a different name
    when it gets saved in its destination.I am not sure if com.oreilly.MultipartRequest class has a feature or not.Can
    anyone help me out of this please.

    you can create files with your own name.
    in temp directory, orielly package creates all the files you uploaded from the client.
    create FileInputStream of file you need , create FileOutputStream with your new name and write the content to it.
    here is some code,
    MultipartRequest multi = new MultipartRequest(req,tempUserFile.getAbsolutePath(),100*1024*1024); // current dir
              Enumeration files = multi.getFileNames(); // Collection of files
              // it sends to you with the form
              String fileName=null;
              String name =null;
              while(files.hasMoreElements())
                   name = (String)files.nextElement();
                   File f = multi.getFile(name);
                   fileName = multi.getFilesystemName(name);
                   FileInputStream fis = new FileInputStream(f);
    FileOutputStream fos = new FileOutputStream//create outputstreamwith your new name
    now dump contents of inputstream to outputstream.
    hope this helps.
    raheem

  • Accessing files within the Network

    Hi
    I have problem with file sharing. Within the network I have a PC with windows Vista. It has file sharing on. But it is not showing any files in my MAC. Can anyone tell me how to change the settings in my MAC to access files from my PC within the network.

    Hi Avi,
    Thanks for your reply.
    Just to give to some background info. The java class is called from a package that is owned by the same schema. The schema owner is part of the dba_role and connect_role.
    The network drive on the windows 2000 serveris mapped by the domain administrator account.
    We have given permissions to the schema owner to access the mapped drive thru java.
    What the java script does is fill a string array with the name of each file in the directory. The script and error messages are below.
    I have a feeling that the schema account does not have windows 2000 permissions to access network resources, but it is just a hunch.
    Regards,
    Ned
    public static String[] getDirList(String dir, String FilterExt)
    System.out.println(dir + ' ' + FilterExt);
    FilenameFilter filter= new FilterExt(FilterExt);
    File DirList = new File(dir);
    String f[] = DirList.list(filter);
    System.out.println(f.length);
    for (int i = 0; i < f.length; i++)
    System.out.println(f.toString());
    return f;
    java.lang.NullPointerException
    at ImpExpUtil.getDirList(IMPEXPUTIL.java:2254)
    at AutoImpExp.getNewImportFile(AUTOIMPEXP.java:87)
    at AutoImpExp.Import(AUTOIMPEXP.java:253)
    at Tester.autoImportExport(TESTER.java:2135)

Maybe you are looking for

  • Loading a large data

    Can anyone help me in loading this data by helping me fix my table to fix all my data ? ========================= TABLE ========================= CREATE table NEC (NecID number(20) not null, title nvarchar2(500), Code nvarchar2(255), desc nvarchar2(2

  • HT4528 how do i open a locked iphone 4

    My son went past the allowed password input screens and now the phone will not unlock and i have tried to connect to itunes with no help. Itunes says I need to unlock phone and iphone says I need to connect to Itunes!!!

  • How do i keep my ipad from disconnecting from wifi when it goes to sleep

    I use my iPad mini for grades at school.  Everytime the iPad goes to sleep, it loses the WiFi connection and I have to log in again.  How can I keep the WiFi connected?

  • JDeveloper - Database Applet

    Hi! I just got Jdeveloper 2.0 Beta, and trying to go through the tutorial. I have completed the Database Applet Tutorial successfully and it works fine within Jdeveloper. Then I did the Deployment part in order to run this applet in a Web environment

  • Cronology error

    i am running a job through CRONOLOGY tool which is job scheduler tool. The job which i m running is generally run once in a month. The issue i am facing is, whenever the job is run for the very first time in a month, it shows one ORA error but it goe