Java 11.6
I am trying to write a java class that will take in a filename as a parameter then read line by line of that file. After it is done reading it will convert the file to equivalent morse code. My other methods such as "print morse table" "convert string to morse" works as it should but for the file function, every time I type the file name it just gives me an empty output. Not sure where exactly is the problem. I am posting the method underneath.
public void encodeFile(String s){
try{
BufferedReader br = new BufferedReader(new FileReader(s));
while((br.readLine()) != null){
String st="";
if( st ==" "||st==null){
System.out.println("");
}else{
int length = st.length();
for(int i=0;i<length;i++){
char c = st.charAt(i);
int x = c;
if(x>96 && x<123){
c = Character.toUpperCase(c);
}
if(c==' '){
System.out.printf(" ");
}else{
for(int j=0; j<listCodes.length; j++){
if(c==listCodes[j].getCharacter()){
System.out.printf(listCodes[j].getEncoding() + " ");
break;
}
if(listCodes[j+1]==null){
System.out.printf("?");
break;
}
}
}
}
}
System.out.printf("%n");
}
br.close();
}catch (Exception e){
System.out.println("java.lang.Exception: Invalid File Name: " + s);
}
}