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

  • Home
  • SEARCH
  • 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 936813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:22:23+00:00 2026-05-15T21:22:23+00:00

Possible Duplicate: “using” keyword in java I’m transitioning from C# to java, so please

  • 0

Possible Duplicate:
“using” keyword in java

I’m transitioning from C# to java, so please bear with me…

When reading a file in C#, you simply wrap it all in a big ‘using’ block, so that if you have an exception, the file will still be closed. Like so (maybe inaccurate but you get the idea):

using(FileStream fs = new FileStream("c:\\myfile.txt")) {
  // Any exceptions while reading the file here won't leave the file open
}

Is there a convenient equivalent in java 5 or 6? I get the impression that lately java has been ‘borrowing’ some of the syntactic sugar from c# (such as foreach) and so i wouldn’t be surprised if there’s a java equivalent of using these days.

Or do i just have to use a try..finally block? ‘Using’ is just so much nicer i think…

  • 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-15T21:22:24+00:00Added an answer on May 15, 2026 at 9:22 pm

    There’s no equivalent syntax sugar using statements in Java 5 or 6. However, a proposal for automatic resource management which adds a familiar Disposable interface seems to have been accepted for Java 7 . Until then, you have to manually code a try…finally.

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

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do this using INFORMATION_SCHEMA tables, as well as… May 17, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Well, considering that (fib n) causes n-1 calls to fib-helper,… May 17, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer You can't indeed access your application using http://square/square/public Using the… May 17, 2026 at 1:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: ‘CONTINUE’ keyword in Oracle 10g PL/SQL I am Using Oracle 9i and
Possible Duplicate: casting vs using the ‘as’ keyword in the CLR hi, can somebody
Possible Duplicate: “BigInt” in C? Hey there! I'm calculating the Fibonacci numbers in C
Possible Duplicate: Are “(function ( ) { } ) ( )” and “(function (
Possible Duplicate: is “else if” faster than “switch() case” ? I've encountered a lot
Possible Duplicate: ASP.NET “special” tags What is the difference between <%# ... %> ,
Possible Duplicate: ASP.NET “special” tags I hope this isn't too much of a newbie
Possible Duplicate: Why am I getting an “Out of memory” error with Perl's XML::Simple?
Possible Duplicate: In C#, should I use string.Empty or String.Empty or “” ? I

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.