
I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea?
import java.lang.String;
import java.io.*;
import java.util.*;
public class CountVowels
{
public static void main(String args[])throws IOException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String:");
String text = bf.readLine();
int count = 0;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c=='*' ) {
count++;
}
}
System.out.println("The number of vowels in the given sentence are " + count);
}
}

The given code counts the number of vowels present in the text file data.
import java.io.*;
public class CountVowels {
public static void main(String[] args)throws Exception{
try{
FileInputStream fstream = new FileInputStream("c:/data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int count=0;
String str="",st="";
char ch;
while((str=br.readLine())!=null){
st+=str;
}
for (int i=0;i<st.length();i++){
ch = st.charAt(i);
if(( ch == 'a') ||( ch == 'e') ||( ch == 'i') ||( ch == 'o') ||( ch == 'u')){
count++;
}
}
System.out.println("Number of vowels in the file: "+count);
br.close();
}
catch (Exception e) {
System.err.println(e);
}
}
}

Thanks.. worked great
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.