mercredi 8 avril 2015

Why does this function not work properly in an "if" statement

I try to call a function,"removeLineFromFile", to remove a line in a .txt file, given by @Narek, on: Find a line in a file and remove it (the second answer, by vote).


1) If I put it here, it works very well:


Part of the structure is:



public class cs1{
public static void main (String[] args) throws Exception{

cs1 k = new cs1();
***k.removeLineFromFile(file1,args[0]);***


Testmain tf3 = new Testmain();

if(tf4[1].length()!=0){
if(!tf4[1].trim().equals(tf5[3].trim())){
...............


2) But if I put it in the if-else condition, it always return: "Could not delete file"



public class cs1{
public static void main (String[] args) throws Exception{


cs1 k = new cs1();

Testmain tf3 = new Testmain();

if(tf4[1].length()!=0){
if(!tf4[1].trim().equals(tf5[3].trim())){
***k.removeLineFromFile(file1,args[0]);***
...............


Could anyone tell me why? This is so odd.


Aucun commentaire:

Enregistrer un commentaire