{"id":67488,"date":"2021-07-23T04:10:05","date_gmt":"2021-07-23T08:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/count-chars-in-a-file-pretty-simple-java-code-java\/"},"modified":"2021-07-23T04:10:05","modified_gmt":"2021-07-23T08:10:05","slug":"count-chars-in-a-file-pretty-simple-java-code-java","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=67488","title":{"rendered":"Count Chars in a File : Pretty Simple Java Code #Java"},"content":{"rendered":"<pre>\r\n\r\n\/*\r\n * Copyright (c) 1995, 2008, Oracle and\/or its affiliates. All rights reserved.\r\n *\r\n * Redistribution and use in source and binary forms, with or without\r\n * modification, are permitted provided that the following conditions\r\n * are met:\r\n *\r\n *   - Redistributions of source code must retain the above copyright\r\n *     notice, this list of conditions and the following disclaimer.\r\n *\r\n *   - Redistributions in binary form must reproduce the above copyright\r\n *     notice, this list of conditions and the following disclaimer in the\r\n *     documentation and\/or other materials provided with the distribution.\r\n *\r\n *   - Neither the name of Oracle or the names of its\r\n *     contributors may be used to endorse or promote products derived\r\n *     from this software without specific prior written permission.\r\n *\r\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\r\n * IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r\n * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\n * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r\n * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r\n * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r\n * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r\n * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r\n * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r\n * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n *\/ \r\n\r\nimport java.io.*;\r\n\r\npublic class Count {\r\n    public static void countChars(InputStream in) throws IOException\r\n    {\r\n        int count = 0;\r\n\r\n        while (in.read() != -1)\r\n            count++;\r\n\r\n        System.out.println(\"Counted \" + count + \" chars.\");\r\n    }\r\n\r\n    public static void main(String[] args) throws Exception\r\n    {\r\n        if (args.length &gt;= 1)\r\n            countChars(new FileInputStream(args[0]));\r\n        else\r\n            System.err.println(\"Usage: Count filename\");\r\n    }\r\n}\r\n\r\n<\/pre>\n<p> From: http:\/\/sitestree.com\/?p=10877<br \/> Categories:Java<br \/>Tags:<br \/> Post Data:2017-07-20 20:24:24<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* * Copyright (c) 1995, 2008, Oracle and\/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * &#8211; Redistributions of source code must retain the above copyright * notice, this list of &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=67488\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-67488","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":67486,"url":"http:\/\/bangla.sitestree.com\/?p=67486","url_meta":{"origin":67488,"position":0},"title":"Get System Property: Pretty Simple Java Code #Java","author":"Author-Check- Article-or-Video","date":"July 23, 2021","format":false,"excerpt":"\/* * Copyright (c) 1995, 2008, Oracle and\/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24457,"url":"http:\/\/bangla.sitestree.com\/?p=24457","url_meta":{"origin":67488,"position":1},"title":"Implement your Own Permission: Pretty Simple Java Code #Root","author":"Author-Check- Article-or-Video","date":"April 10, 2021","format":false,"excerpt":"Implementing Your Own Permission package com.gamedev.games; import java.io.*; import java.security.*; import java.util.Hashtable; import com.scoredev.scores.*; public class ExampleGame { public static void main(String args[]) throws Exception { HighScore hs = new HighScore(\"ExampleGame\"); if (args.length == 0) usage(); if (args[0].equals(\"set\")) { hs.setHighScore(Integer.parseInt(args[1])); } else if (args[0].equals(\"get\")) { System.out.println(\"score = \"+ hs.getHighScore()); }\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":66326,"url":"http:\/\/bangla.sitestree.com\/?p=66326","url_meta":{"origin":67488,"position":2},"title":"Skeleton of the Ant File #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Ant can be used to compile and deploy Java applications. Struts and Spring applications also make use of Ant. Here, we have provided the structure of the build.xml file with examples that is used to carry out the functionalities. The redistribution of this file is in compatible with the copyright\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10059,"url":"http:\/\/bangla.sitestree.com\/?p=10059","url_meta":{"origin":67488,"position":3},"title":"Transform binary representation into integral number using bitset","author":"","date":"July 27, 2015","format":false,"excerpt":"\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> #include\u00a0<string> #include\u00a0<limits> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0print\u00a0some\u00a0numbers\u00a0in\u00a0binary\u00a0representation \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0short>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0long>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"10,000,000\u00a0with\u00a024\u00a0bits:\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<24>(1e7)\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/*\u00a0transform\u00a0binary\u00a0representation\u00a0into\u00a0integral\u00a0number \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"\\\"1000101011\\\"\u00a0as\u00a0number:\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<100>(string(\"1000101011\")).to_ulong()\u00a0<<\u00a0endl; } \u00a0\/*\u00a0 267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a00000000100001011 267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a000000000000000000000000100001011 10,000,000\u00a0with\u00a024\u00a0bits:\u00a0100110001001011010000000 1000101011\"\u00a0as\u00a0number:\u00a0\u00a0555 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 \/\/ create a bitset that is 8 bits long bitset<8> bs;\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":62223,"url":"http:\/\/bangla.sitestree.com\/?p=62223","url_meta":{"origin":67488,"position":4},"title":"Transform binary representation into integral number using bitset #Programming Code Examples #C++ #Bitset","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"\u00a0 \u00a0 \/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> #include\u00a0<string> #include\u00a0<limits> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0print\u00a0some\u00a0numbers\u00a0in\u00a0binary\u00a0representation \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0short>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0long>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"10,000,000\u00a0with\u00a024\u00a0bits:\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<24>(1e7)\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/*\u00a0transform\u00a0binary\u00a0representation\u00a0into\u00a0integral\u00a0number \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"\"1000101011\"\u00a0as\u00a0number:\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<100>(string(\"1000101011\")).to_ulong()\u00a0<<\u00a0endl; } \u00a0\/*\u00a0 267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a00000000100001011 267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a000000000000000000000000100001011 10,000,000\u00a0with\u00a024\u00a0bits:\u00a0100110001001011010000000 1000101011\"\u00a0as\u00a0number:\u00a0\u00a0555 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 \/\/ create a bitset that is 8 bits long\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27162,"url":"http:\/\/bangla.sitestree.com\/?p=27162","url_meta":{"origin":67488,"position":5},"title":"Pointers #Programming Code Examples #Java\/J2EE\/J2ME #Ajax","author":"Author-Check- Article-or-Video","date":"May 12, 2021","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/67488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67488"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/67488\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67488"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}