tag:blogger.com,1999:blog-694855878384792308.post3043922645783772646..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to read file in Java using Scanner Example - text filesjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-694855878384792308.post-63983440623820210792020-10-08T21:23:44.313-07:002020-10-08T21:23:44.313-07:00you can just write into the file and when you flus...you can just write into the file and when you flush it will be saved. See here for an example about <a href="https://javarevisited.blogspot.com/2011/12/read-and-write-text-file-java.html#axzz6aLRJ581T" rel="nofollow">how to write data into a text file in Java</a> javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-24921120376675674362020-10-08T19:44:01.021-07:002020-10-08T19:44:01.021-07:00how do we save it to a new file? so I am able to p...how do we save it to a new file? so I am able to print it and is displayed perfectly. But now I want to save it to a new file for me to open it as a text. Thank YouAnonymoushttps://www.blogger.com/profile/05344581886283699705noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-78152065931374987392020-03-20T07:17:34.310-07:002020-03-20T07:17:34.310-07:00Hello Abhishek, I have shared a lot of exampls of ...Hello Abhishek, I have shared a lot of exampls of Scanner class, you can search for it<br />here are a couple of them<br />https://javarevisited.blogspot.com/2012/07/read-file-line-by-line-java-example-scanner.html<br />http://javarevisited.blogspot.sg/2012/12/how-to-read-input-from-command-line-in-java.html#axzz5DmwFLA1Kjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-14122426797731614122020-03-19T04:27:46.753-07:002020-03-19T04:27:46.753-07:00HOW TO FETCH THE DATA USING SCANNER CLASS IN JAVA ...HOW TO FETCH THE DATA USING SCANNER CLASS IN JAVA ...PLZ DESCRIBE AS COMMENT IN CODEABHISHEKhttps://www.blogger.com/profile/17644277033186294110noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-8385273034735158232020-02-06T03:35:53.863-08:002020-02-06T03:35:53.863-08:00I don't remember top of my head but there shou...I don't remember top of my head but there should be an option to move Scanner pointer, check the Java documentation, you will definitely find something. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-77196859311024321022020-02-05T09:17:17.389-08:002020-02-05T09:17:17.389-08:00What if I want the scanner object to start exactl...What if I want the scanner object to start exactly from line 3?, To start reading the lines from line 3 downwards?<br />Anonymoushttps://www.blogger.com/profile/00269893093898198827noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-59534580830830968962019-11-28T21:33:08.639-08:002019-11-28T21:33:08.639-08:00java.please
//write code with proper exceptions h...java.please<br /><br />//write code with proper exceptions handling read the contents <br />//ef the above file using methods of the scanner classAnonymoushttps://www.blogger.com/profile/00019273032236500888noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-23586718197484293022018-01-17T02:09:04.282-08:002018-01-17T02:09:04.282-08:00Good to know your writing.Good to know your writing.Anonymoushttps://www.blogger.com/profile/13016318328819103801noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-34560822564276638742018-01-06T16:56:33.114-08:002018-01-06T16:56:33.114-08:00Hello, I am making a very slow progress learning j...Hello, I am making a very slow progress learning java.<br /><br />Would you be able to help me out and let me know why my data is not displayed after writing the code as below? I am trying to read in a ppm picture, which is white and black and where 255 stands for white and 0 for black. I will need to calculate the number of white lines that are longer than 1/3 of the table size:<br /><br />public<br /> class test {<br /> <br /> <br /><br /> public static final int X = 512;<br /> int count = 0; <br /> int a = 255;<br /><br /> public static void main(String[] args){<br /> int[] data = getData ("C:\\Users\\Joannna\\Desktop\\inData.ppm");<br /> System.out.println(data.length);<br /> System.out.println(data);<br /> }<br /> <br /> public static int[] getData(String path){<br /> try{<br /> Scanner scanner = new Scanner(new File("C:\\Users\\Joannna\\Desktop\\inData.ppm"));<br /> int [] data = new int [X*X];<br /> int i = 0;<br /> while(scanner.hasNextInt()){<br /> data[i++] = scanner.nextInt();<br /> scanner.nextInt();<br /> scanner.nextInt();<br /> }<br /> return data;<br /> }catch(Exception io){<br /> System.out.println(io);<br /> return null;<br /> }<br /> } <br /> <br />}Asiackhttps://www.blogger.com/profile/18107440462605153799noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-50998447733807707812016-09-17T21:17:20.586-07:002016-09-17T21:17:20.586-07:00I want to clean & scaning temp file in j2me. W...I want to clean & scaning temp file in j2me. What is the code of scaning and cleaningAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-68843461986481666082016-06-28T21:57:38.999-07:002016-06-28T21:57:38.999-07:00Here is the old way to read a plain text file in J...Here is the <a href="http://javarevisited.blogspot.com/2011/12/read-and-write-text-file-java.html" rel="nofollow">old way to read a plain text file in Java</a>. It uses FileInputStream instead of FileReader to read text file. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-87883168104223260322015-09-18T09:22:21.272-07:002015-09-18T09:22:21.272-07:00The statement
import java.io.FileNotFoundExcepti...The statement <br />import java.io.FileNotFoundException; <br />just makes it easier to use the Exception class java.io.FileNotFoundException. It doesn't import any class, it just makes a name easier to use. You just need to write FileNotFoundException instead of the full name.<br />So it doesn't have anything to do with any Java libraries (Jar files).<br /><br />When the program create a new File object, it will throw a java.io.FileNotFoundException object which contains an error code if the named file doesn't exists.<br /><br />As there are no try ... catch that handles that exception in the main method, the method main must then be declared to be expected to generate such an error to everyone that calls the main method.Unknownhttps://www.blogger.com/profile/07739151575590190186noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-9476689561945449472015-01-08T10:10:16.525-08:002015-01-08T10:10:16.525-08:00It's a library, contains the class FileNotFoun...It's a library, contains the class FileNotFoundException which is used for throwing a exception in case of not find any input text file.Anonymoushttps://www.blogger.com/profile/04645412830244084373noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-47528455639038225282014-11-12T05:37:55.398-08:002014-11-12T05:37:55.398-08:00Its a library in order the compiler to understand ...Its a library in order the compiler to understand what is File for exampleAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-37428823964575349172014-10-14T05:51:20.936-07:002014-10-14T05:51:20.936-07:00import java.io.FileNotFoundException;
Why is thi...import java.io.FileNotFoundException;<br /> Why is this line put ?? What is the function of it??Anonymousnoreply@blogger.com