Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:34:21+00:00 2026-05-26T13:34:21+00:00

I have this small code File source; if ( !source.exists() ) { source =

  • 0

I have this small code

    File source;
    if ( !source.exists() ) {
        source = new File("instances/student"+student.getStudentID()+".data");
    }

The problem is, source is not initialized. Since the whole point is to check if it exists, how do I avoid this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:34:22+00:00Added an answer on May 26, 2026 at 1:34 pm

    Create a File object.

    File source = new File(...);
    

    What constructor you use depends on how you want to locate a file. A simple path String could be enough.

    EDIT: just realized the source of your confusion may be that you think creating the File object will try to locate the file or create it on the file system. That’s not the case. Just calling new File(...) won’t check its existence or try to create it. A File object is simply an abstraction for a path in your file system. It could be a directory as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small code library that I'm considering releasing into Open Source. I
I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
Say I have this small function in a source file static void foo() {}
Work on this small test application to learn threading/locking. I have the following code,
So I am obviously not a very good programmer. I have written this small
Suppose you have some source code that comes from the unix world. This source
I have this small SQL query. SELECT a.`id` , a.`title` , a.`date` , (
I have this small class called City that simply holds some information about a
In my c# application i have this small form which is used to set
In CodeIgniter I'm using a base CRUD My_model , but I have this small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.