Quote:
Originally Posted by rushnitrkl22
hii everyone!!!
Heres a code for writing a string stored in resp_str to a file in thge path specified but I dont get the required string in the output file...I just get an empty file....
pls help me..as to why it is happening...theres no error which I get!!!
Regards Punit
-
File output=new File("D:\\Punit\\Output.txt");
-
boolean a=output.exists();
-
System.out.println("the file exists??"+a); //true
-
a=output.canWrite();
-
System.out.println("the file can be written :"+a); //true
-
PrintWriter pw = new PrintWriter(new FileWriter(output));
-
String resp_str=resp.toString();
-
int lenStr=resp_str.length();
-
int i=0;
-
while(lenStr>0){
-
pw.write(resp_str.charAt(i));
-
i++;
-
lenStr--;
-
}
Add a few debugging prints such as:
-
System.out.println("resp_str: "+resp_str);
-
System.out.println("length: "+lenStr);
add them just before that while loop and see what happens. You do close that
file after you've finished printing do you?
kind regards,
Jos