Windows 7 and file input

With the following code, it throws an error while trying to instantiate the scanner because apparently the file doesn't exist. I've tried putting the file in multiple places and using both absolute and relative paths. I am assuming the issue is with Windows 7. Any ideas?
        File file = null;
        Scanner scan = null;
        try{
            //JOptionPane.showMessageDialog(null,File.exists("C:\\Users\\stephen\\Documents\\javaprojects\\file.txt")); //also tried it with / and just file.txt
            file = new File("file.txt");
            JOptionPane.showMessageDialog(null,file.exists());
            scan = new Scanner(file);
        catch (Exception ex){JOptionPane.showMessageDialog(null,"Error while opening file"); System.exit(0);}

stephensk8s wrote:
If by user.dir you mean the directory that the program is in, then yes, I have it in there and have tried to access it from there.No, I mean user.dir which can be obtained from System properties. Based on your answer to my question, I am willing to bet you any amount that the error is neither Java's nor Windows 7.
edit: if you place this in your code:
System.out.println(System.getProperty("user.dir"));and place the file in this directory, will your program now work?
Edited by: Encephalopathic on Oct 16, 2009 5:57 PM

Similar Messages

  • Getting parameters from text and file input tag. .  canyou help me ?

    Hello!
    Is there anyway of getting parameters from an
    text field input in a form like :
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >Actually I would like to insert the parameters and make the upload of an file
    on the same form. It is something likethis :
    Form.jsp
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >   
    <input type="text" id="name" name="signinName" />
    <input name="signinFile" id="fileUp" type="file" />   
    <input type="submit" id="submit_btn" name="signinSubmit"/>uploadingFile.jsp
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
    .//upload the file
    String email = request.getParameter("signinName").trim(); //this line is bringing me an NullPointerException
    %>Thanks in advance for any suggestion!!
    All the best!

    You cannot use the HttpServletRequest object to retrieve parameters from a multipart form. You'll have to use a package that can parse such a form. I suggest Apache commons FileUpload.
    http://jakarta.apache.org/commons/fileupload/
    Using this package you can get both the file upload and any other parameters.

  • Swing labels and file input

    Okay, let's see if i can explain this in one go...
    I have a file reader class as below:
    package chineseanimals;
    import java.io.*;
    public class AnimalFileReader {
        public AnimalFileReader (String filename) {
             try{
    FileReader fr = new FileReader(filename);
    BufferedReader br = new BufferedReader(fr);
    String s;
    while((s = br.readLine()) != null) {
    System.out.println(s);
    fr.close();
          catch (Exception e)
            {   System.err.println("File input error");
    }This is called up through:
    AnimalFileReader animalFile = new AnimalFileReader(animal.toString().toLowerCase() + ".txt");
    finalAnimal = animalFile.toString();
      public String getFinalAnimal() {
            return finalAnimal;
        }(Part of the Chineseanimals class .getAnimalFile method)
    Which altogether is ran by this:
    private void getAnimalsActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
        String year = tempYear.getSelectedItem().toString(); //tempYear is obtained through a JComboBox
        Chineseanimals getAnimals = new Chineseanimals(year);/* year is convertee into an animal for use in the animal.toString().toLowerCase() above*/
        getAnimals.getAnimalFile();
        resultsLabel.setText(getAnimals.getFinalAnimal());
    }It prints the file no problem, in the NetBeans output box. However, at the Swing label i get:
    chineseanimals.AnimalFileReader@c1cd1fHopefully that all makes some sort of sense. Ultimately i want to get it so that the resultLabel (which is a swing jLabel) displays the contents of the file read at (animal.toString().toLowerCase() + ".txt").
    Where am i going wrong?

    I'm going to assume your questions were rhetorical (mainly because i can't be bothered to answer them) and designed to point me in the right direction as well as make me think i was able to find my own answer.
    Which i did, (completely by myself, that is).

  • Info window and file sizes

    I've been transitioning into Lion for about half a day now and most new features are welcome.  However I can't figure out why the info window displays the size of a file in bytes then displays it in Gigabytes, megabytes etc.  How on earth is this easier to read?  Is this perhaps a bug and not an improvement??
    For Example:
    Lion: 7,043,089,832 bytes (7.07 GB on disk) for 13,115 items
    Snow Leopard:  7.07 GB on disk (7,043.......bytes)
    I apologize if it seems very nitpicky but it takes about two seconds more to figure out the files attributes (and I use the info window quite a bit).
    I suppose I could open the infowindow nib file with interface builder and swap them (the filesize templates) but a hassle...anyone else annoyed/confused with this new layout??
    Thanks!
    ASIDE FROM THE SMALL ANOYANCES, LION IS FANTASTIC!

    typod16 wrote:
    For Example:
    Yes I understood the ⌘-i   part,  I did not grok the copy and paste in red part. 
    Thanks the  example pics was a great help.
    In all honesty it looks the same to me as always,  but I will take your word on it.
    I see it as a non issue.
    There are many instances of the nuances of calculating differences if you want to be pedantic:
    df -h
    vs
    df -H
    DESCRIPTION
         The df utility displays statistics about the amount of free disk space on
         the specified filesystem or on the filesystem of which file is a part.
         Values are displayed in 512-byte per block counts.  If neither a file or
         a filesystem operand is specified, statistics for all mounted filesystems
         are displayed (subject to the -t option below).
         The following options are available:
         -a      Show all mount points, including those that were mounted with the
                 MNT_IGNORE flag.
         -b      Use 512-byte blocks rather than the default.  Note that this
                 overrides the BLOCKSIZE specification from the environment.
         -g      Use 1073741824-byte (1-Gbyte) blocks rather than the default.
                 Note that this overrides the BLOCKSIZE specification from the
                 environment.
         -H      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte,
                 Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
                 number of digits to three or less using base 10 for sizes.
         -h      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte,
                 Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
                 number of digits to three or less using base 2 for sizes.
         -i      Include statistics on the number of free inodes.
         -k      Use 1024-byte (1-Kbyte) blocks rather than the default.  Note
                 that this overrides the BLOCKSIZE specification from the environ-
                 ment.

  • Hi All,  I am trying to install informatica 9.1 HF 2 connecting to 11g DB.  when installing Informatica, I am at the DOMAIN CREATION windows and inputting the DB connect details and for some reason, it cannot connect to the DB.  The DB is running   any id

    Hi All,
    I am trying to install informatica 9.1 HF 2 connecting to 11g DB.
    when installing Informatica, I am at the DOMAIN CREATION windows and inputting the DB connect details and for some reason, it cannot connect to the DB.
    The DB is running
    any ideas?
    the error message states:
    THE CONNECTION FAILED: CORRECT THE DATABASE INFO AND TEST THE CONNECTION AGAIN..any help please
    thanks

    Yup, that did it.
    I actually had been made aware of the patch when I downloaded CF, but for some reason I thought it was difficult to install (I thought that you could only use the installer package if you could open Administrator). IAC I downloaded the appropriate patch file, ran it and Administrator ran. There was something in the install notes about reconfiguring the websites and removing the IIS6 Management feature but I'm not going to fool with anything because right now at least CF is running.
    Thanks.

  • When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....

    When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....
    Could some one give help and let me know where I can probably find the settings option that allows me to change and switch to previous situation where it was possible to decide time to time how to proceed either opening the file or saving it ??
    Thanks in advance
    David

    What is your operating system?
    Open a PDF from where?  If online, in what browser?

  • How to create popup window with radio buttons and a input field

    Hi Guys,
    Can somebody give some directions to create a stand alone program to create a window popup with 2 radio button and an input field for getting text value. I need to update the text value in a custom table.
    I will call this stand alone program from an user exit. 
    Please give me the guidance how go about it or please give any tutorial you have.
    Thanks,
    Mini

    Hi,
    There are multiple aspects of your requirements. So let's take them one at a time.
    You can achieve it in the report program or you can use a combination of the both along.
    You can create a standalone report program using the ABAP Editor (SE38). In the report program you can call the SAP Module pool program by CALL Screen <screen number>. And then in the module pool program you an create a subscreen and can handle the window popup with 2 radio button and an input field for getting the text.
    For help - Module Pool programs you can search in ABAP Editor with DEMODYNPRO* and you will ge the entire demo code for all dialog related code.
    For Report and other Module pool help you can have a look at the following:
    http://help.sap.com/saphelp_nw70/helpdata/en/47/a1ff9b8d0c0986e10000000a42189c/frameset.htm
    Hope this helps. Let me know if you need any more details.
    Thanks,
    Samantak.

  • I am trying to open PDF files from safari, but when I click on them they open in a separate window and the information is encrypted. Any ideas on how to get them to open them in Adobe? Any help please!

    I am trying to open PDF files from safari, but when I click on them they open in a separate window and the information is encrypted. Any ideas on how to get them to open them in Adobe? Any help please!

    The pdf is loading as html code. If you save it, it will download as :
    605124.pdf.html
    Change the extension to .pdf
    And it opens and works perfectly, I just tested it:
    Use this link to download it automatically:
    http://saladeaula.estacio.br/arquivo.asp?dir=00/1020624/605124.pdf&num_seq=59828 4

  • Can't access the "Apple" icon in upper main menu to shutdown my MacBook Pro running 10.6.8!  Also can't open a new finder window and main menus such as File and Edit are sluggish to open or don't open at all.  Doesn't happen each time I attempt to shutdow

    Can't access the "Apple" icon in upper main menu to shutdown my MacBook Pro running 10.6.8!  Also can't open a new finder window and main menus such as File and Edit are sluggish to open or don't open at all.  Doesn't happen each time I attempt to shutdowCan't

    There are some keyboard commands (shortcuts) you can use instead of having to go to the Apple menu -
    Control-Eject          This brings up the Restart-Sleep-Cancel-Shutdown window.
    Command-Option-Eject          This puts the machine to sleep.
    Command-Control-Eject          This closes all apps and restarts the machine.
    Command-Option-Control-Eject          This closes all apps and shuts the machine down.

  • Want to open a new browser window and display the html file in locale disk.

    Hi,
    I want to open a new browser window and display the html file in local drive. The below html applet work in local system successfully. But i deploy the same in web server (Tomcat) and try the same in client machine it does not work. Please help.
    Note:
    The class below fileopen.FileOpen.class i make it as a jar and put it in jre\ext folder at the client machine.
    ------------------------------------FileOpen.html(Tomcat)-----------------------------------------------------
    <html>
    <body >
    <applet code="OpenFile.class" archive="loadfile.jar" width="100" height="100">
    <param name="path" value="file://c:/open.html" />
    </applet>
    </body>
    </html>
    -------------OpenFile.java in server(Tomcat)--------------------------------------------
    public class OpenFile extends Applet implements ActionListener{
    String path = "";
    fileopen.FileOpen open = null;
    Button b = null;
    public void init(){
    path = getParameter("path");
    b = new Button("Open");
    b.addActionListener(this);
    add(b);
    public void actionPerformed(ActionEvent ae){
    try
    open = new fileopen.FileOpen(this,path);
    catch (Exception e){
    e.printStackTrace();
    -------------------------------------------FileOpen.java /Client JRE/ext----------------------------------------------------
    package fileopen;
    public class FileOpen
    AppletContext context = null;
    URL url = null;
    public FileOpen(Applet applet,String path)
    try
    if(null != applet){
    context = applet.getAppletContext();
    if (null != path)
    url = new URL(path);
    context.showDocument(url, "_blank");
    }catch(Exception ex)
    ex.printStackTrace();
    Please help to solve this issue very urgent.
    Thanks in advance.
    By,
    Saravanan.K.

    zzsara wrote:
    I want to open a new browser window and display the html file in local drive. ...Did you ever pause to consider how ridiculous that is?
    The best audience for applets is people off the internet. 'People off the internet' might be using a computer that has no (what was it?) 'open.html' in the root of the C: drive. In fact (shock horror) they may not even be running Windows, and would therefore probably have no 'C:' drive at all.
    If you do not intend to distribute this to people off the web, an application makes a lot more sense, but even then, you cannot rely on the document being there unless you 'put it there' (during installation, for instance).
    As the other poster intimated, applets can load documents off the local disk as long as they are trusted. Here is an example*, but note that it is not so rash as to presume any particular path or file, and instead leaves it to the user to choose the document to display.
    * The short code can be seen at SDNShare on the [Defensive Loading of Trusted Applets|http://sdnshare.sun.com/view.jsp?id=2315] post.
    On the other hand, a sandboxed applet can load any document coming from its own server via URL, or get showDocument(URL) to work. In that case, the JRE must recognize that the URL is from its own server, so the best way to form URLs for applet use is via the URL constructor
    new URL(getDocumentBase(), "path/to/open.html");That is how I form the URL in this [ sandboxed example of formatting source|http://pscode.org/fmt/sbx.html?url=/jh%2FHelpSetter.java&col=2&fnt=2&tab=2&ln=0]. Of course, in this case the applet loads the document, then parses the text to draw the formatted version, but the point is that an URL produced this way will work with showDocument(URL).
    I am pretty sure showDocument() in an applet off the internet will work with an URL pointing to a foreign (not its own) server, but it will not be able to load documents off the end user's local disks.
    I suggest a couple of things.
    - Try to express this problem in terms of what feature it is that you want to offer the end user. Your question jumps directly to a bad strategy for achieving ..who knows what? An example of a feature is "Shows the applet 'help' files on pressing F1".
    - A good way to indicate interest in a solution is to offer [Duke stars|http://wikis.sun.com/display/SunForums/Duke+Stars+Program+Overview] to match that interest.
    Edit 1:
    ..and please figure out how to use the CODE tags.
    Edited by: AndrewThompson64 on Sep 12, 2008 11:14 PM

  • Ever since the latest update, my task bar (if it's called that - it's the one with "file,edit,view, etc") will "grey out" and I won't be able to type into any websites I visit. Only way to fix:either restart Firefox or reduce the window and open it again.

    Ever since the latest update, my task bar (if it's called that - it's the one with "file,edit,view, etc") will "grey out" and I won't be able to type into any websites I visit. Only way I can proceed is if either restart Firefox (very annoying) or reduce the window and open it again. Please help!

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    See also:
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *http://kb.mozillazine.org/Corrupt_localstore.rdf

  • Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...

    Okay, i have 2 bugs with maverick.  First, when I delete a file within a window, the files deletes but the preview doesn't delete until I close the window and reopen it.  Second, I work on a network of computers and the search feature is now buggy...  When I search for a file, A) it asks me if it's a name, or it wont produce anything, and B), its slower than in prior OS versions and in some instances I have to toggle to a different directory and go back to my original directory in the search: menu bar or the search wont produce anything...  Very buggy. 

    It appears to me that network file access is buggy in Maverick.
    In my case I have a USB Drive attached to airport extreme (new model) and when I open folders on that drive they all appear empty. If I right click and I select get info after a few minutes! I get a list of the content.
    It makes impossible navigate a directory tree.
    File access has been trashed in Maverick.
    They have improved (read broken) Finder. I need to manage a way to downgrade to Lion again.

  • I have an iPad 2 and iPhone 4 and for them I use I cloud I have also 1 pc windows and at work place I use windows pc ; until now my files are stored on an external disk drive could' I use iCloud to perform the backup of my external disk drive ? Thanks

    I have an iPad 2 and iPhone 4 and for them I use I cloud I have also 1 pc windows and at work place I use windows pc ; until now my files are stored on an external disk drive could' I use iCloud to perform the backup of my external disk drive ? Thanks
    Loredano

    These are the options you have.
    Budget $1299.
    http://www.apple.com/macbookair/
    http://www.apple.com/macbookpro/
    Best.

  • When downloading is complete, I can not see, run, nor access the file; it only appears in the "Downloads" window (and not the specified folder) and the only options permitted are to delete it, or to go to the download web site; what's blocking it?

    My PC's OS is 'MS Windows Vista Home Premium'. As my initil question states: When downloading, after the download completes, I can not see, run, nor access the file in it's designated folder. The download only appears in the "Downloads" window and the only "Right Click" options permitted are to "Remove From List", "Select All", & "Copy Download Link" I also can not double click to run it. What's blocking it?
    I have a similar problem when accessing .zip files that are attachments to my emails. Here, however, I can place the file in a designated folder, however, the .zip file and it's compressed content files are file-typed as "FireFox Document" and I get permissions errors when running an unzip tool.
    Why are my download files being quarantined ??? Is there a security setting option I need to change???
    To get around this, I'm using IE to download and install these files, but switching back & forth between FireFox & IE is a real pain.

    It's your anti-virus not working correctly while scanning. You can turn off the option to scan in Firefox's '''about:config''' by filtering for '''browser.download.manager.scanWhenDone''' and double-clicking that line to change the value to '''false'''

  • Multiple drag emails from Mail to a finder window and for it to name the files as the subject heading

    Hi
    I have been using Mac's now for about 10 years and this is my first problem.
    I have recently moved into an office that use PC's with a Windows server.
    I have set up the network to transfer files and view the windows server and it  works fine.
    I have a problem in that my colleagues on PC need to be able to view my emails which I send and receive using Mail. They therefore need to have logical title names and the date sent and ideally who to or from. I view them and archive them using Mail which is fine for me.
    I understand about the archiving and copying of mailboxes but this gives every email the un-fathomable title name 9944847 etc.
    I can get round the problem by dragging and dropping every email I send and receive individually and it will automatically give it a more logical title of the subject heading however the date is when it was dragged not when sent. This is a pain if I am away or forget to save an email for a day or two and then the date is inconsistent.
    Is there a way to batch copy emails from Mail to a finder window and for it to name the files as the subject heading or to archive the files in a similar way so they retain the detailed information my colleagues require.
    And no I can not get to all change to Mac and I don't really fancy using Outlook, Entourage or Parallels.
    Please help.
    Toby

    Quit Mail. Force quit if necessary.
    Back up all data. That means you know you can restore the Mail database, no matter what happens.
    Triple-click the text on the line below to select it:
    ~/Library/Mail/V2/MailData/Envelope Index
    Copy the selected text to the Clipboard (command-C). In the Finder, select
    Go ▹ Go to Folder
    from the menu bar. Paste into the box that opens (command-V), then press return.
    A Finder window will open with a file selected. Move the selected file to the Desktop, leaving the window open. Other files in the folder may have names that begin with "Envelope Index". Move those files, if any, to the Trash. Relaunch Mail. It should prompt you to re-import your messages. You may get a warning that the index is corrupt and that Mail has to quit. Click OK.
    Test. If Mail now works as expected, you can delete the file you moved to the Desktop. If you get a warning that the file is in use when you try to empty the Trash, log out and log back in.

Maybe you are looking for