Java 如何从一个以某个字母开头的文件中删除某个单词并将其放入新文件中?

Java 如何从一个以某个字母开头的文件中删除某个单词并将其放入新文件中?,java,Java,我的任务是从文件中删除某个单词的所有匹配项。使用已创建的文本文件。我正在使用效忠誓言创建一个名为filtered.txt的新文件,删除以给定字母开头的所有单词。向用户索要您要使用的信函 因此,我有效忠誓约文本: I pledge Allegiance to the flag of the United States of America and to the Republic for which it stands, one nation under God, indivisible, with

我的任务是从文件中删除某个单词的所有匹配项。使用已创建的文本文件。我正在使用效忠誓言创建一个名为filtered.txt的新文件,删除以给定字母开头的所有单词。向用户索要您要使用的信函

因此,我有效忠誓约文本:

I pledge Allegiance to the flag
of the United States of America
and to the Republic for which it stands,
one nation under God, indivisible,
with Liberty and Justice for all.
如果使用字母“a”,则应为:

I pledge to the flag
of the United States of
and to the Republic for which it stands,
one nation under God, indivisible,
with Liberty Justice for.
当我的程序是大写字母时,它不工作

import java.io.*;
import java.util.*;
   public class filteredWords{
      public static void main(String[] args)throws FileNotFoundException{
         PrintWriter writer = new PrintWriter(new File("filteredWords.txt"));
         Scanner input = new Scanner(System.in);
         Scanner reader = new Scanner(new File("pledge.txt"));
         System.out.println("What letter would you like to use?");
         char letter = input.next().charAt(0);
         while(reader.hasNextLine()){
            String word= reader.next();
            for(int i = 0; i<=0; i++){
               char ch = word.charAt(i);
               if(ch!=letter){
                  writer.print(word+" ");
                  word=reader.next();
               }
            }
         }
         writer.close();
      }
   }
import java.io.*;
导入java.util.*;
公共类过滤词{
公共静态void main(字符串[]args)引发FileNotFoundException{
PrintWriter writer=新的PrintWriter(新文件(“filteredWords.txt”);
扫描仪输入=新扫描仪(System.in);
扫描仪阅读器=新扫描仪(新文件(“质押文件”);
System.out.println(“您希望使用什么字母?”);
字符字母=input.next().charAt(0);
while(reader.hasNextLine()){
String word=reader.next();
对于(int i=0;i对于字符,'A'!='A'。

在进行比较之前,可以使用Character.toLowerCase(char)将第一个字母转换为小写。

for循环看起来可疑:i