Why the file constructor does not take exception?

Hello

I was wondering why the file class constructor doesn't have an exception verified where the path to the file would be wrong or the file does not exist.

For example, if we use a Scanner to read a file, the Scanner manufacturer made throws FileNotFoundException.
Why do Java only checks here and not when the file object is created? What is behind all this?
File inFile = new File("c:/myfile.txt"); 
Scanner sc = new Scanner(inFile);  // can throw FileNotFoundException
Thanks in advance for your comments.

lemonboston wrote:
Hello

I was wondering why the file class constructor doesn't have an exception verified where the path to the file would be wrong or the file does not exist.

Because a file object can validly represent a path that does not actually exist on the file system.

For example, if we use a Scanner to read a file, the Scanner manufacturer made throws FileNotFoundException.

Because, while that file simply represents a path that may or may not exist, scan will attempt to read from the path you give, so that the file must exist for Scanner to do its job. It sometimes makes sense to represent a non-existent path, but it is never logical to try to read it.

Tags: Java

Similar Questions

  • I have 9, 1 pages in PDF files that are accessible and the need to combine them into 1 PDF file.  I tried adding, adding and the combine process of PDF files. The file created does not take my changes. The file created is partially accessible, but I have

    I have 9, 1 pages in PDF files that are accessible and the need to combine them into 1 PDF file.  I tried adding, adding and the combine process of PDF files. The file created does not take my changes. The file created is partially accessible, but I have to re - the problems that I had fixed in the unique files. I need suggestions on what else can be done, if any. Using Acrobat pro XI.

    By habit, I tend to combine PDF files in the Page pane by right-clicking thumbnails then 'Insert of Pages'-> 'From File'. For me, this preserves the tags of these two documents, although the tags may have to be moved to the correct location (if I remember correctly the tags for inserted pages are put at the end of the tag structure, regardless of where the pages are inserted), if I put the tags in the document to insert into a container as a Section tag It makes the process easier. Travel set of tags in the right place is the only re-fixing that I remember having to do. What behavior you encounter?

    a 'C' student

  • Why the file size does not change when I use "Process multiple Images" to add a watermark?

    Hello

    I use 11 elements. To add a watermark to a lot of JPG photos at the same time, I use the function 'process multiple files.

    I select a source folder and a destination folder and adds a number to three numbers for each file. I do NOT check the box marked 'change photo size. After that, I set the watermark I want printed on my photos and hit OK. All files in the source folder are processed and saved with a new name in the destination folder. Loyally.

    But. The file size of the new file is strongly reduced, compared to the original. He's going from 10 MB to 500 KB (in general). Why is this? Is there a way I can help?

    Kind regards

    / Mikael Lindgren

    File size reduction is the effect of jpeg compression. In the process several files dialog, check the bottom option "convert files to the format" and choose "jpeg max quality.

  • Error: "the file is maybe damaged. the file header does not match the checksum calculated"during the installation of Windows 7/8

    * Original title: Question of re-Installation of operating system.

    I got the message during win 7 / Win 8 installation.

    "the file is maybe damaged. the file header does not match the checksum calculated.

    My config - processor Intel C2D, 2 GB of RAM, Intel motherboard, 500 GB HARD drive

    I have also replace Win 7 DVD and DVD player also replaced.

    I also reinstall my single RAM chip so many times. but the problem still exists.

    During Win XP SP 3 installation, no such message type not displayed. I can install it easily.

    Pls help me Sir, I would like to Win7 in my computer again.

    Hello

    Thanks for posting your query on the Microsoft Community.

    According to the description of the problem, it seems that you are facing the question with the reinstallation of Windows 7 on your computer.

    Because the computer does not recognize the CD - R into the DVD player probably boot order is set to hard drive first. I suggest to change the DVD boot priority in the BIOS and then try to perform the Startup Repair.

    Note: BIOS change / semiconductor (CMOS) to complementary metal oxide settings can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the configuration of the BIOS/CMOS settings can be solved. Changes to settings are at your own risk.

    In order to make changes in the BIOS, I suggest you to contact the manufacturer of the computer.

    Method 1:

    Unplug all external devices connected to the computer with the exception of the keyboard and mouse and check if the problem persists.

    M odes 2:

    If the problem persists try the Startup Repair. It is one of the recovery tools in the System Recovery Options menu. This set of tools is on your computer's hard disk and on the Windows installation disc. To learn more about Startup Repair , you can refer to the below mentioned article:

    http://Windows.Microsoft.com/en-us/Windows7/Startup-Repair-frequently-asked-questions

    Method 3:

    In addition, if startup repair is not enough, you can perform a system restore, check if it helps you to solve the problem. For reference, you can see the article mentioned below.

    What are the system recovery options in Windows 7?

    http://Windows.Microsoft.com/en-us/Windows7/what-are-the-system-recovery-options-in-Windows-7

    Note: when you perform the system restore to restore the computer to a previous state, programs and updates that you have installed are removed.

    Hope it would help. If problem persists always post back with the current state of your computer and the result of the proposed suggestion, we will be happy to help you.

    Kind regards

  • By pressing the home button does not take me to the home screen of iOS 9.3.3

    I have recenly updated upgraded to iOS 9.3.3 and I noticed that pressing the home button does not take me to the home screen. The only way to get there is by using the creature of multitasking. (double pressing the home button) Also, some applications seem to freeze if turn my phone off and then turn it back on, or when I access it via the multitasking function. Can someone please help?

    Try a forced reboot. Hold down the Home and Sleep/Wake buttons at the same time for about 15 seconds, until the Apple logo appears. You won't lose anything.

    If a force restart does not help, try a system restore. First save your device via iTunes. Also import your photos on your computer and copy all the important data. Reconstruction of the support first test and test. If this does not help, you may need to restore as a new and reconfigure from scratch as the backup may be damaged. It is important to have your photos and your saved data separately from the backup. Here are the steps for a restoration:

    https://support.Apple.com/en-us/HT201252

  • Why the MacBook Air does not recognize my Adobe ID?

    I have a paid Adobe ID.

    I would like to use to install the Adobe CC, I know to be available for a total of two computers.

    I am currently using, like many Mac pro.

    But there was a problem.

    I also have a Macbook air.

    MacBook air into account is not active.

    ID payment is complete and is active in the MacBook Pro.

    Not available for the MacBook Air why?

    The MacBook Air does not show the message log on another commitment signed in devices.

    Just again once this to tell me, 'make a payment '. But I already paid!

    Why the MacBook Air does not recognize my Adobe ID?

    Troubleshooting FAQ: What should I do if I have a subscription, but my application acts as if I had a trial?

  • Why the original image does not appear on my desktop and not Wo one?

    Why the original image does not appear on my desktop and not Wo one?

    I made adjustments to an image that shows himself such that adjusted with the symbols at the bottom right of the image.
    I tried to drag and drop and he transferred the original image.

    The adjusted picture can be transferred and what I need to do or I do something wrong?

    Thank you

    Greg,

    Claes has pretty much nailed. You will do well to spend time to learn how Lightroom works. He is not like most software that you've used before, and if you don't understand what it does and how it does, you stand a good chance of losing your images.

    Try googling 'Lightroom tutorials' or 'get started in Lightroom. It's not rocket science, but it's different.

    HAL

  • Why the CC lightroom does not recognize my users folder when you try to import?  I can not imaport images in the program.  It has worked well in the past

    Why the CC lightroom does not recognize my users folder when you try to import?  I can not imaport images in the program.  It has worked well in the past

    It is an Apple problem. They obviously fixed with a change to iTunes. Download the update on their part.

    HAL

  • Why the serial number does not appear after typing the code out of the card I bought?

    Why the serial number does not appear after typing the code out of the card I bought?

    See the following topics:

    Using redemption code

    --------------------

    http://helpx.Adobe.com/x-productkb/global/redemption-code-help.html

  • The file reference does not call. upload()

    OK it's going to take a little bit to explain but stick with me:

    I have two layers in the timeline, with no keyframes (coucheUn) and the other with a picture any key for every frame in the layer (layerB).
    In coucheUn, I have the script action to declare a variable of FileReference and I also declare and attach a listener object to the file reference.
    The listener object detects the event .onSelect to the FileRefernce (this event is generated when the service. the FileReference class's browse() is called - which opens a file browser and allows you to select a file). When called onSelect listener object executes the function. upload() FileReference which analyzes the file selected to a php script that downloads the file on my server.
    Function. for the FileReference browse() is called from an image in layerB. This is where the weird stuff that happens.
    When I test the movie the first time I enter the keyframe that calls the function. browse() all download routine work and the file is downloaded successfully. If I continue to the next keyframe (using navigation controls) and then navigate back and try to repeat the download process, then the file browser opens successfully, I select the file and then nothing happens. I have problems to identify the problem, for as far as I see it is as if it does never emit the onSelect event once the file is selected, which shouldn't be the case that the function .Browse works and a file is selected successfully. This would imply the php script does not work which is just ridiculous because it is a very simple script and it works the first time.
    Everyone has ideas, if you need more just information!


    UPDATE:

    Just did some tests and I'm completely confused, it's something the onSelect event. For some reason, it is not called / is not detected by the listener object. It's just weird because he calls good the first time you enter the frame, but if you navigate back, it is not detected. I checked the listener object was still in the scope of this framework and it seems to be, so I'm completely confused. The listener object is there and listening, the event that generated the onSelect event is executed but then never detected.

    Wooops, corrected just, said an another FileReference var on the following image with the same name, changed the name and works very well. Really really stupid of me.

  • Why the STOP button does not stop this vi?

    Hello

    I took an example of Labview 2011 called "soul hollow period-Low Freq 1 Ctr.vi. This example vi measures one period, but, I want to measure the period over and over again, so I put it in a WHILE loop, but the STOP button does not stop at the vi.  Instead, I have to use ABORT to stop the vi...

    How can I stop this vi?

    Dave

    It does not replace the time-out.  The while loop is a separate beast from the meter reading.  You wouldn't want your loop due to always make you miss the error messages, would you?

    Usually just clear the error message of time-out on the counters.

    You get the message twice because the loop runs in fact twice.  The first time the stop button is read as false as soon as the loop begins.  Then you click on it.  At the same time that it takes 10 seconds for the timeout counter to occur - when he does it gives you the error.  Then, the loop runs again.  This time it reads the key stop as true, because you clicked on it during the timeout of 10 seconds of the last loop.

    A time loop allows everything inside to complete execution before the end, then you will have to wait for an another timeout of 10 seconds to occur which produces another error.

    Unless you need a measure of very, very low frequencies I set your time-out to a more reasonable number and simply erase the mistake if it matches 200474.

  • I hosted my server windows with dad go but the file server does not

    I greeted WindowsServer 2008 in go daddy with cisco firewall .i have set up active directory and server files but when I try to map the file server in my clients over the internet, it does not work

    his problems with the firewall they had put in place for me

  • "pointing to the file" tool does not work

    I use Dreamweaver CS4 on a Mac under OS X 10.5.6. The tool 'to the file' (the icon that looks like a target in the properties panel) does not work. When I click on & made slide on it nothing happens. Any ideas on how I can get it to work?

    dmmontana wrote:

    I use Dreamweaver CS4 on a Mac under OS X 10.5.6. The tool 'to the file' (the icon that looks like a target in the properties panel) does not work.

    There is a known issue point to the file on Mac if you use a big screen (I think only 20 ' or more) or on a Setup dual monitor. It works very well on smaller screens.

  • Why the mouse keys does not work?

    I would use MouseKeys in windows to use my keyboard as a mouse, but I was not able to get the function runs.

    I am able to activate the MouseKeys without any problem, but by pressing the keys on the numeric keypad does not move the pointer of the mouse at all.

    I can see the mouse keys icon in the notification area of the taskbar of windows 7 and I am able to switch between the left and right mouse buttons using the / and - keys on the keyboard, but that's all I can do.

    Anyone have any ideas on what I can do?

    Thank you

    Jason

    Hi, thanks for your response.

    I found the solution to my problem. Keys mouse was working, but I didn't know it because my mouse speed setting is set to minimum. Although it seemed that nothing was happening when I was pressing the keys on the numeric keypad, the mouse began in fact to move, but only very slowly.

    I adjusted my settings of the mouse, and the mouse keys now work properly.

    Thanks again

    Jason

  • validation of the email does not take exception to emailID with consecutive.

    I use javax.mail.jar 1.5.2

    Validation of the email does not throw AddressException for e-mail with consecutive. as [email protected] which, according to RFC822, should generate exceptions.

    Is there any solution for this?

    Kind regards

    Naveen

    N °

    It would be nice if JavaMail did a more complete job of checking the syntax of an e-mail address, at least in 'strict', but 'invalid' mode addresses meet quite frequently, and syntax checking does not tell you if the address is actually valid, so JavaMail he leaves to the mail server to make the actual validation.

Maybe you are looking for