Should i close reader or inputstream ?

for buffered writer classes, i know that i have to close so that it can flush the buffer.
i wonder what's the need for closing stream which is opened for reading?
thank you

Both readers and writers should be closed when you don't need the streams anymore. Maybe it doesnt seem necessary to close a stream, but its a good programming practise to do so. If you read from a file, I think it can hold a lock on the file so you can't read it from another program until your java program exits. And if it's a socket connection, you could easily use all the allowed connections (on windows at least) if you don't close them.
The buffered writer class has a flush method you can use if you want to keep the stream open.

Similar Messages

  • Why should we close a connection

    Hi,
    Connection conn = DriverManager.getConnection (databaseUrl, userName, userPassword);
    Why should we close a connection
    conn.close();
    Even when i give no "close command", it works !
    Thank You
    Edited by: ashipj on ?? ????????, ???? ?:?? ???????

    My code frequently fetches data from database, so i created a class like this
    public class ConnectToDatabase
    /*             public ConnectToDatabase()
                                    Connection conn;
         public ResultSet selectS(String userQuery) throws Exception
              String userName = "root";
              String userPassword = "gal";
              String databaseUrl = "jdbc:mysql://localhost:3306/test";
              Class.forName ("com.mysql.jdbc.Driver");
              Connection conn = DriverManager.getConnection (databaseUrl, userName, userPassword);
              String query = userQuery;
              Statement S=conn.createStatement();
              ResultSet RS=S.executeQuery(query);
                                    //conn.close;
              return RS;
                                    //conn.close;
    /*              public void closeConnection()
                                    conn.close;
    }and from the main code i make call as given below (it works fine)
    ConnectToDatabase CTD=new ConnectToDatabase();
    ResultSet result=CTD.selectS(String userQuery);
    //CTD.closeConnection();Now my problem is
    1) If try to give "conn.close()" before "return RS;" It will show error (RS cannot be fetched after closing connectio)
    2) If write conn.close after return it wont be executed (ofcourse - unreachable statement)
    3) If use "CTD.closeConnection();" it gives errror saying that "cannot find conn(in closeConnection()) " i dont know why constructor is noy loaded.

  • How to read an inputStream in UTF-8 into a byte array.

    Hi, Java version is 1.4.2. If inputStream.read() is used to read the bytes into a byte array, is it guarenteed that UTF-8 chars are correctly transferred into byte array? Or should we use InputStreamReader? An example would be a great help.
    Thanks in advance.

    I would like to send a byte array read from InputStream to another app where they are converted to UTF-8. In brief
    -Read input stream which comes in UTF-8 into a byte array
    -Send byte array to another app which will convert it into UTF-8 characters

  • Should I close close Parallels before installing Mountain Lion?

    Should I close Parallels before installing Mountain Lion?

    Thanks, William, for the speedy reply.  I hope I'm one of the lucky ones that can give the update 5 stars.  I upgraded my Parallels to version 8 and found a slight speed increase. Everything is backed up in case the upgrade causes problems.

  • Having problems opening a pdf file with reader 10/11 get error msg cannot open close reader and try again any ideas

    having problems opening a pdf file with reader 10/11 get error msg cannot open close reader and try again any ideas

    Hi George ,
    Is it happening with all the PDF' or any specific one?
    Could you please share the error message so that we can replicate at our end ?
    Try repairing reader  once and see if that fixes the issue.
    Launch Reader>Navigate to Help>Repair Adobe Reader Installation
    Regards
    Sukrit Dhingra

  • PowerPivot: MidTier process account should have 'Full Read' permission on all associated SPWebApplications.

    First time install of SharePoint 2013 (with SQL Server 2014) and Health Analyzer continuously shows the error in subject line.  Note that I've 'Reanalyzed' the error and attempted to 'Repair Automatically' but no luck.  I've followed the instructions
    on related threads for this issue but to no avail.
    Verified that the service account used by the App Pool has Full Read access on the web site as below.
    First verified what App Pool is being used by the PowerPivot application:
    Then verified what domain account is used as the service identity for the App Pool (under Service Accounts, but I can only upload 2 images per post).  The Service Account for the SharePoint Web Services System is <mydomain>\SPServices
    Then checked that the domain account has Full Read on the web site
    Any help of ways I can additionally troubleshoot would be greatly appreciated...

    Hi Dinesh,
    Please use another domain account for PowerPivot Service Application instead of SP_farm, then grant full read permission to the content web applications associated to this service application through User Policy, then run the rule and check result again.
    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e864c2ff-19ce-439a-a11f-935c6b7240a4/powerpivot-midtier-process-account-should-have-full-read-permission-on-all-associated?forum=sharepointadmin (Rajat's
    suggestion)
    http://whitepages.unlimitedviz.com/2012/06/the-health-analyzer-and-powerpivot-for-sharepoint/
    Thanks,
    Daniel Yang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you
    have feedback for TechNet Subscriber Support, contact [email protected]
    Daniel Yang
    TechNet Community Support

  • Is there a certain number of times I should install Adobe Reader on a mac before it works?

    Is there a certain number of times I should install Adobe Reader on a mac before it works?  Cant open any Adobe certified pdf's in any applications. Keeps telling me to install Reader for the best experience.
    I've tried that on three macs, no luck.  Website in general is a shambles.

    No, if it doesn't work the first time, doing it again isn't likely to change anything.
    The usual reason for this message is that the app is not using Reader, but the PDF needs Reader. What app is putting out the message? Can you reply (NOT BY EMAIL) with a screen shot of the message?

  • MenuBar should not close when menuitem is selected

    MenuBar should not close when menuitem is selected so that user can check multiple menu items

    PopUp a List instead.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • EntityManagerFactory - when should be close ?

    Hi ,
    I am using TOPLINK and getting after some time of application running an Error :
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    This is probably because I am closing EntityManagerFactory, and than calling it again with out checking (emf.isOpen())...
    OK my fault, but the main question is , should I close EntityManagerFactory after done job, and than every time when I need it again opening ?
    Or leave open as a private Attribute ? :
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestModel", new java.util.HashMap<String, String>());thank you, greetings
    andrzej
    Edited by: andrzej76 on Aug 30, 2010 1:30 AM

    Hi ,
    I am using TOPLINK and getting after some time of application running an Error :
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    This is probably because I am closing EntityManagerFactory, and than calling it again with out checking (emf.isOpen())...
    OK my fault, but the main question is , should I close EntityManagerFactory after done job, and than every time when I need it again opening ?
    Or leave open as a private Attribute ? :
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestModel", new java.util.HashMap<String, String>());thank you, greetings
    andrzej
    Edited by: andrzej76 on Aug 30, 2010 1:30 AM

  • Reader and InputStream

    I notice it is fairly easy to create a reader for an input stream.
       Reader reader = new InputStreamReader( in );However, I don't see any easy way to create an input stream from a reader.
       InputStream in = new ReaderInputStream( reader );Is there an obvious reason for this that I am missing? A reason why someone would never what to do this? Or is there an adapter class that I am just missing?
    As always, thanks in advance,
    R.

    Well, no not really. That's a very specific example (i.e. strings). Basically, I can read content from a variety of places -- the content could come as a ByteArrayInputStream, StringInputStream, FileInputStream and so on -- I won't know which. I use a reader to work with that input stream (possibly filtering it). Then I want to take this content and put it into a database as an InputStream. I can't just use the original input stream because it may have been filtered using a reader. I want to keep these as streams because, in the case that it is a FileInputStream, I don't want to have to load the entire stream into memory as a byte-array. Furthermore, the source content could be binary or text. I want to have two wrapper methods, one that took a Reader and one that took an InputStream. These would them write that data to the database, which is why I was wondering if there was an easy way to wrap a Reader with an InputStream (I already know the reverse is easy). Sounds like I need to introduce another layer of abstraction. Maybe a Content class tree that can get/set an InputStream.

  • Should I close my 2 oldest CCs?

    Here's my rebuild since my 1/31/2011 BK7 discharge: (Card/Date Opened/CLBest Buy Rewards MC 10/14/2011 2,000
    Merrick Bank Visa 12/1/2011 3,100
    Barclays Rewards MC 4/10/2012 3,000 (Was $5700 CL, moved $2700 to NFL)
    Cap One Rewards Visa 10/1/2014 10,000
    Barclays NFL 3/27/2015 7,700 (Just under 60% util w/0% BT)
    BoA Secured 5/13/2015 300
    Discover It 7/7/2015 4,000
    subtotal 30100 Store Cards:Walmart/Synchrony 2/1/2013 5000
    Lowes/synch 1/30/2015 5000 Total Available Credit: $40,100 Total Utilization: 15%, QS & Rewards MC report PIF monthly usage, NFL & Lowes report 0% APR balances, all others report $0 bal I'm probably going to close the 2 oldest CCs by the end of the year. The BB MC was opened with HSBC with a $59 annual fee, it posts in early Nov. I earn more than that in Reward Zone certificates, but now that I have better reward cards why have most of the rewards I earn on that card offset an AF? I plan to call them in Oct and tell them I'm no longer willing to pay any AF. Being Citi I expect them to refuse to waive the AF and if they do I'll tell them "Then close the account immediately". Merrick Bank was an great rebuild card but I've outgrown it with reward cards w/much better CLs. I haven't used it since I got Cap1 QS Oct, but I've been keeping it active by letting 2 small monthly bills totaling less than $20 charge to it. I don't expect Merrick to be happy with that for much longer and will take AA by lowering the CL, which would prompt me to close it - that's what happened to my Target Redcard. That Bank of America secured card that looks so out of place opened just this last May? I had 1 CC from them included in my BK7 and want to eventually get a Fidelity Amex, so I wanted to get back in with them. Plan to app to convert to unsecured early next year, and then app for Fidelity Amex in 2017 when all 9 derogatory IIB accounts fall off CR. I've budgeted an agressive payment schedule on the NFL card to get the balance down below 30% util by Dec. even though the 0% BT (used to payoff a Prosper loan) doesn't expire untill Fall 2016, that high.util dings my CS. At that point I'll app for Sallie Mae and think the SL will offset the loss of $5100 in CLs from closing BB MC & Merrick. I'm not worried about the hit to my AAoA, the advice here is that closing cards does not affect your AAoA, and AAoA only has medium impact anyway. Thoughts?

    NRB525 wrote:
    AAoA, likely is not affected too much by closing the accounts, however...You have some balances still, so if the Merrick doesn't have an AF, there's no reason to close that. You've got a basic charge flow going through there. They might close or CLD it, but why speed up the uncertainty? Let it ride. It may take them 3 years to get around to doing anything. Or never. Thanks for the advice. No, I won't take any action on Merrick, only react if they do a CLD or close. Yeah, I learned the hard way with Target Redcard dont' sockdrawer, I didn't use if for almost a year and they lowered the CL from $1k to $200 and I never could get them to raise it back even with small monthly usage. So as long as Merrick is happy with $20/mo usage I'm good with that. My Merrick card never had any fees while many of the newly issued cards have an AF, so I just suspect they're not going to be happy with no fees and no 25+% APR balances from me for very long._____________________________________________________________________________Good luck with the Best Buy change, to no AF. I don't have any experience with that, but it's something you might want to start the conversation earlier, try to PC to no AF. Keeping that account open, if you are earning rewards, keeps that oldest card active and earning. Worth the effort, if you ask me. Well, there is no 'PC', other MyFico members tell me they didn't even know an AF BB card existed. I actually did call last Oct and asked to have the AF waived The rep outright lied to me, telling me "Oh, the Mastercard always has an annual fee". I think that since HSBC issued it with an AF Citi just wants to hang on to it. It does give me 2% rewards for groceries, but the rewards can only be used as certificates to lower the price of a Best Buy purchase, and I just don't shop BB as much as I used to, I'd rather get 2% cashback rewards with Barclays Rewards MC. With no AF I'd keep it, but it's no longer worth $59/yr in fees to me to have it. _______________________________________________________________________________The 0% APR may be "hurting your score" but you are saving money. If it is in your cash flow to get it paid down, fine, but with several new accounts it is unlikely you should be looking at new cards, thus scores not matter. You do want to pay it off prior to the 0% expiration however Well, it is an agessive payment schedule to pay NFL down to 30% util by the end of the year, but then I plan to "coast" with slightly more than the min payment until the 0% nears expiration and budget to PIF before expiration. The first part of the year I'm always scrimping to sock away as much as I can into my IRA as prior year contributions by April 15.

  • Should PreparedStatement close before continue next PreparedStatement ?

    Hi guys,
    For instance, I need to use PreparedStatement for several insert and update like below:
    Connection conn; // got the connection
    PreparedStatement pstmt = conn.prepareStatement("insert ......");
    pstmt.addBatch();
    pstmt.executeBatch();
    *// should I do a pstmt.close() here ?????????*
    pstmt = conn.prepareStatement("update......");
    pstmt.addBatch();
    pstmt.executeBatch();
    Thanks & Regards,
    Mark

    kmthien wrote:
    Yes, I am using apache DBCP and using the example code here :
    http://www.freshblurbs.com/jakarta-commons-dbcp-tutorial#comment-544
    However, In my class, I need to connect to 2 database, 1 is local and another 1 is remote.Location doesn't matter.
    I don't know how to create and initialize 2 connection pooling as when I initialize 2 connection pooling, it jus treated it as 1 only.This is of course completely different from your first question. Did you google?

  • Should I close First Premier now or wait:

    Hello good people I have a dilemma and am wondering if I should close a couple of accounts that are really serving me no purpose. These stupid First Premier cards and a Credit One card. First  Premier like so many others was my first card then Credit One then another First Premier. I also have at the time 3 Capital One cards a Barclay Rewards card and a partially secured BOA card as well as some store cards. I want to close it but do not know all of the pros and cons of doing so. I am only keeping them so my overall cl will be higher especially since I do not have any prime cards or limits over $1300 yet. I want to close them but do not want to shoot myself in the foot what should I do.???

    minicook wrote:
    Hello good people I have a dilemma and am wondering if I should close a couple of accounts that are really serving me no purpose. These stupid First Premier cards and a Credit One card. First  Premier like so many others was my first card then Credit One then another First Premier. I also have at the time 3 Capital One cards a Barclay Rewards card and a partially secured BOA card as well as some store cards. I want to close it but do not know all of the pros and cons of doing so. I am only keeping them so my overall cl will be higher especially since I do not have any prime cards or limits over $1300 yet. I want to close them but do not want to shoot myself in the foot what should I do.???I'd close them for sure. You have much better cards that aren't costing you so much money, so you don't need those cards. Their history will continue to help you for quite some time. If you still have enough credit without them, get rid of them. Utilization shouldn't be an issue. If you will end up going over 70% total utilization every month, I'd reccomend paying the card off in the middle of the month so you're not appearing maxed out. The only other thing to do would be to PIF before statement cut on all but one card and leave 1-9% unpaid until the statement is created, but you should only do that when you're applying for new credit. Overall, they aren't helping you enough to justify their cost.

  • Issue SLFI should open in read only or display mode

    If we open an issue in CRM_DNO_MONITOR we can choose whether the issue
    should be opened in change mode or read mode.
    We can do this by means of >Extra > Settings and then choosing for
    Display or Change in the General tab.
    This way we can read issues as a default setting, this way the issue is
    not locked !! Only if we want to change it we set it to change mode and
    continue with the issue.
    However if we do the same using DSWP or SOLMAN_ISSUE_MGMT the issue is
    always opened in change mode, and results in a lot of locks in the
    system. How can this be changed, is there some kind of customizing for
    this or menu option.
    The handling of issue does not seem to be consistent for the different
    methods in handling them.
    Who has the same problem with locking?
    Who has a working bypass w/o manual switching from change to display?
    Thanks in advance,
    Peter Hendriksen

    Thanks for the reply.
    Anything is welcome at this point.
    And yes, I did try both through PowerShell and through the Unlocker and the behavior is pretty much the same. If the item is checked in, there is no trace that it is locked, if I Check it Out (the only thing I can really do with it) it shows as "LongTerm"
    but then throws the same exception
    Unlocking...
    Error occurred. Details:
    Save Conflict
    Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
       at Microsoft.SharePoint.SPFile.CheckIn(String comment, SPCheckinType checkInType, Boolean bIsMigrate, SPUser modifiedBy)
       at Microsoft.SharePoint.SPFile.CheckIn(String comment)
       at ForceSPItemUnlock.UnlockerForm.UnlockButton_Click(Object sender, EventArgs e)
    The method UpdateItemCheckoutExpiration sounds insteresting though.
    "The more difficult something became, the more rewardant it was in the end"
    http://ftduarte.blogspot.com

  • I cant shut down my macprobook its showing error that safari should be close first but the safari not open

    i have tried to close my macbook pro .but when i ma going to shutdown its showing me error message by saying safari need to be close but the safari is already closed its not geeting shutdown just i can make my mac in sleep mode

    Press option+Carl+escape keys, then in the Force Quit list select Safari. Click Force Quit button, click Confirm.

Maybe you are looking for

  • How to merge cell as Excel  with smartforms ???

    Hi all Gurus of SmartForms, I want to format a template as Excel by using Merge. I means I want Merge 2 cells into 1 and put data into center of new cell. But I dont know how to do that by SmartForms Who can help me step by step? Thanks.

  • Automatic UD for the in-process lots with 03 inspection type

    Kindly provide me the list of steps to perform the Automatic UD for the inprocess lots with 03 inspection type. AYK

  • Saving attachments under Mail 1.3.11 and OSX 10.3.9

    Hi, I appear to be unable to save any attchments that are sent to me in an e-mail, these can be photo's or video clips, whatever. For example, with a photo attachment, if I open the attachment in Preview and select 'Save As' I get the warning 'Save,

  • SD Controlling creation of pricing in VK11 by Condition Type

    Hiii SAPfans, i would like know, it is possible to control the users how maintain pricing by condition type ... example : User A can only maintain pricing for condition type = QPRT USer B can only maintain pricing for condition type = ZABC

  • Have issues with Windows 8.1 been resolved?

    Hi Back when Windows 8.1 first became available I upgraded my Widows 8 installation. I along with many other people had sound problems that could not be resolved at the time. I got random distortion that affected some types of sound and not others, e