473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Simple but not working????

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

Expand|Select|Wrap|Line Numbers
  1. File output=new File("D:\\Punit\\Output.txt");
  2. boolean a=output.exists();
  3. System.out.println("the file exists??"+a);       //true
  4. a=output.canWrite();
  5. System.out.println("the file can be written :"+a);    //true
  6. PrintWriter pw = new PrintWriter(new FileWriter(output));
  7. String resp_str=resp.toString();
  8. int lenStr=resp_str.length();
  9. int i=0;
  10. while(lenStr>0){
  11.     pw.write(resp_str.charAt(i));
  12.     i++;
  13.     lenStr--;
  14. }
May 31 '07 #1
4 1101
JosAH
11,448 Expert 8TB
I moved your question from the Java Articles section to the Java Forum section.
This is the place to ask questions. The Java Articles section is for published
informative (hopefully) articles. Please post your questions in the Java Forum
section. Thanks.

kind regards,

Jos
May 31 '07 #2
JosAH
11,448 Expert 8TB
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

Expand|Select|Wrap|Line Numbers
  1. File output=new File("D:\\Punit\\Output.txt");
  2. boolean a=output.exists();
  3. System.out.println("the file exists??"+a);       //true
  4. a=output.canWrite();
  5. System.out.println("the file can be written :"+a);    //true
  6. PrintWriter pw = new PrintWriter(new FileWriter(output));
  7. String resp_str=resp.toString();
  8. int lenStr=resp_str.length();
  9. int i=0;
  10. while(lenStr>0){
  11.     pw.write(resp_str.charAt(i));
  12.     i++;
  13.     lenStr--;
  14. }
Add a few debugging prints such as:
Expand|Select|Wrap|Line Numbers
  1. System.out.println("resp_str: "+resp_str);
  2. 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
May 31 '07 #3
I wrote the above two linwes...
The string resp_str is displayed and the length of the file is also obtained...
but nothing gets written into the file....
Also u said about closing the file..that I m not doing as I dont knoe how to close the file....
Jun 1 '07 #4
r035198x
13,262 8TB
I wrote the above two linwes...
The string resp_str is displayed and the length of the file is also obtained...
but nothing gets written into the file....
Also u said about closing the file..that I m not doing as I dont knoe how to close the file....
Closing the file is super easy. You just do ..., ah but it's there in the specs for the File class. Look it up.
Jun 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bruce W...1 | last post by:
In my effort to learn PHP I'm playing with some simple email scripts. They worked a few days ago but they stopped working. The only thing I've done to this Windows 2000 PC in this time was a...
3
by: Akseli Mäki | last post by:
Hi, I'm working over my site to include simple CSS. I've now noticed, that the pages look totally different on Opera than compared to Mozilla and IE....
2
by: Chris Leonard | last post by:
I am a C# newbie with experience in other languages who is writing a C# app that talks to a SQL Server. I have the connection working, the queries are working, error handling (try/catch/finally)...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
5
by: Logickle | last post by:
Hi, all. I'm working on an application which requires communicating session info between separate web apps running on the same web server. The out of process server method sounded ideal, and...
2
by: dondraper | last post by:
I have an application that uses a popular but simple set of JavaScript routines that implement an AJAX call used to populate a drop-down. It works for thousands of user but I have one customer...
6
by: sathyashrayan | last post by:
Dear group, Following is a exercise from a book called "Oreilly's practical C programming". I just wanted to do a couple of C programming exercise. I do have K and R book, but let me try some...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
10
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and...
2
by: kigoobe | last post by:
I am having a very weird issue here, a simple form submit not working. Trying for several hours now ... must be something stupid ... help appreciated. First, the html - <form id="formFinale"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.