読み取り中にファイルからスペースを削除しようとしています。これを行うには、char の ASCII コードをチェックします。127 (スペース) でない場合は、それを出力します。
それを考えるより良い方法は何ですか?またはこの方法で修正する方法は?
private FileInputStream sc;
private static char input;
public void openFile(){
try{
sc = new FileInputStream(new File ("D:\\Empty.txt"));
input = (char) sc.read();
if(input != 127){
System.out.println(input);
}
}catch(FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ParsingStrings ps = new ParsingStrings();
ps.openFile();
}