2013-10-16 2 views
0

파일의 데이터를 수정하려고합니다. 성공적으로 파일을 삭제하고 이름을 변경했는지 여부를 확인하는 동안 항상 "Not successfulfully changed"를 인쇄합니다.파일 이름 바꾸기 및 삭제 오류

public void transfer() 
{ 

    File temp=new File("temp.dat"); 
    File supply=new File("supply.dat"); 
    boolean rename=temp.renameTo(supply); 
    boolean delete=supply.delete(); 

    if(delete && rename) 
     Sopln("Successfully Changed"); 
    else 
     Sopln("Not Successfully Changed"); 
}//transfer end 

여기는이 메소드를 호출하는 switch-case 블록입니다. 내 문서를 확인할 때

Sopln("Modify :-"); 
    Sopln("1)Preffered Period"); 
    Sopln("2)Preffered Class"); 
    Sopln("3)Exit"); 
    int option; 
    do 
    { 
     option=Check_Int("Enter Your Choice"); 
     int ctr=0; 
     switch(option) 
     { 
      case 1: Sopln("______________________________"); 
        String name=Check_String("Enter The Name Of The Teacher Whose Details You Want To Change"); 
        String record; 
        while((record=fr.readLine())!=null) 
        { 
         String token[]=record.split("-"); 
         if(name.equalsIgnoreCase(token[0])) 
         { 
          Sopln("Your Current Info:"); 
          Sopln("Name : "+token[0]); 
          Sopln("Preffered Period : "+token[3]); 
          Sopln("Enter Your New Preffered Period"); 
          token[3]=br.readLine(); 
          pw.println(token[0]+"-"+token[1]+"-"+token[2]+"-"+token[3]+"-"+token[4]); 
          ctr++; 
         }//if block end 
         else 
         {pw.println(record);} 
        }//while loop end 
        if(ctr==0) 
        {Sopln("Not Found"); 
        submenu(); 
        } 
        else 
        { 
         ctr=0; 
         transfer(); 
        } 
        fr.close(); 
        pw.close(); 
        break; 
      case 2: Sopln("______________________________"); 
        String name_class=Check_String("Enter The Name Of The Teacher Whose Details You Want To Change"); 
        String record_class; 
        int cnt=0; 
        while((record_class=fr.readLine())!=null) 
        { 
         String token[]=record_class.split("-"); 
         if(name_class.equalsIgnoreCase(token[0])) 
         { 
          Sopln("Your Current Information:-"); 
          Sopln("Name : "+token[0]); 
          Sopln("Preffered Class : "+token[4]); 
          Sopln("Enter Your New Preffered Class"); 
          token[4]=br.readLine(); 
          pw.println(token[0]+"-"+token[1]+"-"+token[2]+"-"+token[3]+"-"+token[4]); 
          cnt++; 
         }//if block end 
         else 
         {pw.println(record_class);}//else block end 
         }//while loop end 
         if(cnt==0) 
         {Sopln("Name Not Found!"); 
         submenu();} 
         else 
         { 
          cnt=0; 
          transfer(); 
         }//else block end 
         fr.close(); 
         pw.close(); 
         break; 
      case 3: main_menu mm=new main_menu(); 
        mm.menu(); 
        break; 
     } 
    }while(option<0 || option>2); 
}//change method end 

는 그렇게, 임시 파일은 필요한 수정 만 생성됩니다,하지만 파일의 이름이 변경되고 있지 않고 원래의 공급 파일이 삭제된다. Plz Help !!

+0

는 반드시 파일 경로가 올바른지 있습니까? – UDPLover

+0

당신은 무엇을 의미합니까? 당신을 얻지 못했습니다 – DragonBlade

+0

어떻게이 프로그램을 운영하고 있습니까? Eclipse 또는 Netbeans IDE 또는 CMD에서 가져 왔습니까? 그리고이 파일들은 어디에 있습니까? – UDPLover

답변

0

먼저 이름을 바꾸고 새 파일 변수 &을 만든 다음 삭제하십시오. 간단한 솔루션.

public void transfer() 

{ // 파일을 파일 온도 = 새로운 파일 ("temp.dat을")의 이름을 변경; 파일 공급 = 새 파일 ("supply.dat"); 부울 rename = temp.renameTo (supply);

//delete file 
File f = new File("supply.dat"); 
boolean delete=supply.delete(); 


if(delete && rename) 
    Sopln("Successfully Changed"); 
else 
    Sopln("Not Successfully Changed"); 

} // 전송 끝

+0

아직 작동하지 않음 :/ – DragonBlade

+0

전송 방법에 버그가 없습니다. –

+0

기다려주세요! 그것은 작동합니다! 이 클래스는 메뉴의 옵션입니다. 그러나 전혀 메뉴의 다른 옵션을 선택한 다음 '수정'을 선택하면 "성공적으로 변경되지 않음"이 표시됩니다. – DragonBlade