updating specific cell csv file using java

前端 未结 5 959
悲哀的现实
悲哀的现实 2020-12-06 15:07

Hi i have a small problem and think i\'m just not getting the correct syntax on one line of code. basically, i can write into my csv file and find a specific record using st

5条回答
  •  日久生厌
    2020-12-06 16:05

    ok i am doing something like this. i can access the csv record pointed to by tokens but it does not update i think incorrect syntax

    private static void ChangeRecord(String sFileName) {
        // TODO Auto-generated method stub
    try {
        BufferedReader r = new BufferedReader(
                            new InputStreamReader(
                            new FileInputStream(sFileName)));
        String line;
        while((line = r.readLine()) != null){
                  String tokens[] = line.split(",");
    
                  String Surname = tokens[1];
                  String network= tokens[2];
                  String city= tokens[4];
                  StringTokenizer StrTok = new StringTokenizer(party);
                  if(StrTok.hasMoreTokens()){
                  if ((city.equals("New York"))&&(Surname.equals("Smith"))){
    
                      String Lovely= "waterloo";
                                       //this line is the one that i think is failing
                      line.replace(network, Lovely);
                      System.out.println(line);
                  }
            }
        }
        r.close();
    } catch(IOException e) {
        System.out.println(" There was an Error Reading the file. " + e.getMessage());
    }
    

提交回复
热议问题