{"id":5347,"date":"2014-03-30T21:01:17","date_gmt":"2014-03-30T21:01:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/error-with-java-fileinputstream-and-fileoutputstream-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:01:17","modified_gmt":"2014-03-30T21:01:17","slug":"error-with-java-fileinputstream-and-fileoutputstream-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/error-with-java-fileinputstream-and-fileoutputstream-collection-of-common-programming-errors\/","title":{"rendered":"Error with java FileInputStream and FileOutputStream-Collection of common programming errors"},"content":{"rendered":"<p>I just made my first I\/O based stuff in Java. I want to check if the content written to a file is properly saved in, or not. For which i wrote the following code..<\/p>\n<pre><code>    import java.io.*;\n\n    public class check implements Serializable {\n        \/\/Make two variables and methods to initialise them\n        private int height;\n        private int width;\n        public void setWidth(int w){\n            width = w;\n        }\n        public void setHeight(int h){\n            height = h;\n        }\n        public static void main(String[] args) {\n\n        check obj = new check();\n        obj.setHeight(20);\n        obj.setWidth(30);\n\n    try{\n        FileOutputStream fs = new FileOutputStream(\"foo.txt\");\n        ObjectOutputStream os = new ObjectOutputStream(fs);\n        os.writeObject(obj);\n        os.close();\n    }\n    catch(IOException ex){\n    }\n    \/\/We set them to null so we can't access the objects on heap.\n      obj = null;  \n\n    \/\/Now we read them back from file   \n    try{\n        ObjectInputStream is = new ObjectInputStream(new FileInputStream(\"foo.txt\")); \n        check stored = (check) is.readObject();\n\n    \/\/Check to see if it worked.\n     System.out.println(\"Variable, stored contains..\" + stored.getType());\n    }\n    catch(IOException ex){\n        }\n\n    }\n }\n<\/code><\/pre>\n<p>But it produces the following error.<\/p>\n<pre><code>Exception in thread \"main\" java.lang.RuntimeException: Uncompilable source code - unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown\n    at check.Check.main(Check.java:33)\n<\/code><\/pre>\n<p>Anyone got any idea to solve the issue?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just made my first I\/O based stuff in Java. I want to check if the content written to a file is properly saved in, or not. For which i wrote the following code.. import java.io.*; public class check implements Serializable { \/\/Make two variables and methods to initialise them private int height; private int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5347","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5347"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5347\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}