Is java.nio.file.Files.newInputStream(myfile.toPath()) better than new FileInputStream(file)?Input and Output Stream Pipe in JavaEfficiency of Java “Double Brace Initialization”?FileInputStream for a generic file SystemHow do I create a file and write to it in Java?How to avoid Java code in JSP files?ObjectInputStream happy with FileInputStream, not happy with getResourceAsStreamIs there a C# equivalent way for Java InputStream and OutputStream?java input output streamWhy is processing a sorted array faster than processing an unsorted array?Why is printing “B” dramatically slower than printing “#”?

Where to pee in London?

Is there such thing as a "3-dimensional surface?"

Validation and verification of mathematical models

Does this put me at risk for identity theft?

What are these circular spots on these Ariane V SRB nozzles?

How to realistically deal with a shield user?

How do I get the =LEFT function in excel, to also take the number zero as the first number?

Does a 4 bladed prop have almost twice the thrust of a 2 bladed prop?

Can ads on a page read my password?

How would a family travel from Indiana to Texas in 1911?

"To go from zero to hero"

Why should public servants be apolitical?

The size of sheafification

How many years before enough atoms of your body are replaced to survive the sudden disappearance of the original body’s atoms?

Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?

How to halve redstone signal strength?

Pronouns when writing from the point of view of a robot

Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?

Was Richard I's imprisonment by Leopold of Austria justified?

Why do private jets such as Gulfstream fly higher than other civilian jets?

Can this code, to convert string to integer, be made more compact?

Print only the last three columns from file

I was contacted by a private bank overseas to get my inheritance

Colleagues speaking another language and it impacts work



Is java.nio.file.Files.newInputStream(myfile.toPath()) better than new FileInputStream(file)?


Input and Output Stream Pipe in JavaEfficiency of Java “Double Brace Initialization”?FileInputStream for a generic file SystemHow do I create a file and write to it in Java?How to avoid Java code in JSP files?ObjectInputStream happy with FileInputStream, not happy with getResourceAsStreamIs there a C# equivalent way for Java InputStream and OutputStream?java input output streamWhy is processing a sorted array faster than processing an unsorted array?Why is printing “B” dramatically slower than printing “#”?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I was using soanr to check my java code, and one issue shows that ,we should use java.nio.file.Files.newInputStream(myfile.toPath()) instead of new FileInputStream(file). And the sonar description is :




This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method, which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected. Java 7 introduced two ways to create streams for reading and writing files that do not have this concern. You should consider switching from these above classes to InputStream is = java.nio.file.Files.newInputStream(myfile.toPath()); OutputStream os = java.nio.file.Files.newOutputStream(myfile.toPath());




My question is, is it right?










share|improve this question


























  • I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

    – user207421
    Mar 27 at 5:16


















0















I was using soanr to check my java code, and one issue shows that ,we should use java.nio.file.Files.newInputStream(myfile.toPath()) instead of new FileInputStream(file). And the sonar description is :




This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method, which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected. Java 7 introduced two ways to create streams for reading and writing files that do not have this concern. You should consider switching from these above classes to InputStream is = java.nio.file.Files.newInputStream(myfile.toPath()); OutputStream os = java.nio.file.Files.newOutputStream(myfile.toPath());




My question is, is it right?










share|improve this question


























  • I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

    – user207421
    Mar 27 at 5:16














0












0








0








I was using soanr to check my java code, and one issue shows that ,we should use java.nio.file.Files.newInputStream(myfile.toPath()) instead of new FileInputStream(file). And the sonar description is :




This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method, which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected. Java 7 introduced two ways to create streams for reading and writing files that do not have this concern. You should consider switching from these above classes to InputStream is = java.nio.file.Files.newInputStream(myfile.toPath()); OutputStream os = java.nio.file.Files.newOutputStream(myfile.toPath());




My question is, is it right?










share|improve this question
















I was using soanr to check my java code, and one issue shows that ,we should use java.nio.file.Files.newInputStream(myfile.toPath()) instead of new FileInputStream(file). And the sonar description is :




This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method, which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected. Java 7 introduced two ways to create streams for reading and writing files that do not have this concern. You should consider switching from these above classes to InputStream is = java.nio.file.Files.newInputStream(myfile.toPath()); OutputStream os = java.nio.file.Files.newOutputStream(myfile.toPath());




My question is, is it right?







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 5:08









user207421

268k28 gold badges226 silver badges381 bronze badges




268k28 gold badges226 silver badges381 bronze badges










asked Mar 27 at 5:02









Yin KevinYin Kevin

11 bronze badge




11 bronze badge















  • I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

    – user207421
    Mar 27 at 5:16


















  • I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

    – user207421
    Mar 27 at 5:16

















I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

– user207421
Mar 27 at 5:16






I'd be astonished. There's nothing about it being finalizer-free in the Javadoc.

– user207421
Mar 27 at 5:16













1 Answer
1






active

oldest

votes


















0














That is a dense statement. Thus, it might be worth to break it into smaller chunk.
First thing first,




This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method




This is true and false. the function itself has been marked as deprecated since java 9. And, it has been removed 5 months ago. So, depending on java version you used. It probably still exists (assuming most people are still using java 8). See this commit for more information.




which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected




Yeah, because, finalize function is invoked after GC. Then, most likely, the object would linger on the heap longer. See javadoc for finalize function here.




Java 7 introduced two ways to create streams for reading and writing files that do not have this concern




True, I have checked the source code in openjdk repo. And, I don't see the implementation of classes that those two functions use implement the finalize method. See the repo here






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370117%2fis-java-nio-file-files-newinputstreammyfile-topath-better-than-new-fileinput%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    That is a dense statement. Thus, it might be worth to break it into smaller chunk.
    First thing first,




    This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method




    This is true and false. the function itself has been marked as deprecated since java 9. And, it has been removed 5 months ago. So, depending on java version you used. It probably still exists (assuming most people are still using java 8). See this commit for more information.




    which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected




    Yeah, because, finalize function is invoked after GC. Then, most likely, the object would linger on the heap longer. See javadoc for finalize function here.




    Java 7 introduced two ways to create streams for reading and writing files that do not have this concern




    True, I have checked the source code in openjdk repo. And, I don't see the implementation of classes that those two functions use implement the finalize method. See the repo here






    share|improve this answer





























      0














      That is a dense statement. Thus, it might be worth to break it into smaller chunk.
      First thing first,




      This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method




      This is true and false. the function itself has been marked as deprecated since java 9. And, it has been removed 5 months ago. So, depending on java version you used. It probably still exists (assuming most people are still using java 8). See this commit for more information.




      which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected




      Yeah, because, finalize function is invoked after GC. Then, most likely, the object would linger on the heap longer. See javadoc for finalize function here.




      Java 7 introduced two ways to create streams for reading and writing files that do not have this concern




      True, I have checked the source code in openjdk repo. And, I don't see the implementation of classes that those two functions use implement the finalize method. See the repo here






      share|improve this answer



























        0












        0








        0







        That is a dense statement. Thus, it might be worth to break it into smaller chunk.
        First thing first,




        This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method




        This is true and false. the function itself has been marked as deprecated since java 9. And, it has been removed 5 months ago. So, depending on java version you used. It probably still exists (assuming most people are still using java 8). See this commit for more information.




        which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected




        Yeah, because, finalize function is invoked after GC. Then, most likely, the object would linger on the heap longer. See javadoc for finalize function here.




        Java 7 introduced two ways to create streams for reading and writing files that do not have this concern




        True, I have checked the source code in openjdk repo. And, I don't see the implementation of classes that those two functions use implement the finalize method. See the repo here






        share|improve this answer













        That is a dense statement. Thus, it might be worth to break it into smaller chunk.
        First thing first,




        This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both of these classes implement a finalize method




        This is true and false. the function itself has been marked as deprecated since java 9. And, it has been removed 5 months ago. So, depending on java version you used. It probably still exists (assuming most people are still using java 8). See this commit for more information.




        which means that objects created will likely hang around until a full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much longer than expected




        Yeah, because, finalize function is invoked after GC. Then, most likely, the object would linger on the heap longer. See javadoc for finalize function here.




        Java 7 introduced two ways to create streams for reading and writing files that do not have this concern




        True, I have checked the source code in openjdk repo. And, I don't see the implementation of classes that those two functions use implement the finalize method. See the repo here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 5:31









        kucing_terbangkucing_terbang

        3,6002 gold badges14 silver badges24 bronze badges




        3,6002 gold badges14 silver badges24 bronze badges



















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370117%2fis-java-nio-file-files-newinputstreammyfile-topath-better-than-new-fileinput%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현