Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

need simple mathod to count the characters in java from txt file.

$
0
0
this is my code which simply read a file. i just want to add method to it that can count the characters in the text file. please anyone, who can tell me about this code. and about that counter characters method.

regards.
Hasnat Rasool













import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FileRead
{
static int count=0;

public static void main(String[] args)
{
File file = new File("a.txt");

try {
FileInputStream fis = new FileInputStream(file);
char current;
while (fis.available() > 0)
{

current = (char) fis.read();
System.out.print(current);
}

}
catch (IOException e)
{
e.printStackTrace();
}
}
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>