• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O example  RSS feed

 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everybody its Vibhas i am an Beginer and Preparing for SCJP .....
Can anybody please help me in following topics :-
1>Give me an example of How to write in a txt file using PrintWriter by passing String as an Key Constructor argument and also Writer class reference as Key Constructor argument...

2> Also Also give me an example of How to write in a file using BufferedWriter ...
Please give me the code for all these and any links on these topics
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Java Tutorials. We don't do people's work for them; think how much better you will remember it if you have looked it up yourself.
 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey sorry dude i did'nt got examples in code that helps me please someone give some code examples.....
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean, you didn't get any code examples? That tutorial is full of code examples. Those examples don't do precisely what you're asking for, but if you work through the tutorial -which you need to do in order to actually understand I/O- you will be able to put together code that does what you're asking for.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want me to program your application, please send a cheque.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find a lot of short code examples in the The Java Developers Almanac.
 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys please don't misunderstand me i am giving you a simple code please tell why this code is unable to write in the file "vibhas.txt" although this code compiles and run as well. I am a begineer so kindly try to motivate me inspite of demotivating Here is the code:-

I have tried with both PrinWriter class and BufferedWriter class to write in the file but that file did'nt contain the word " Hello dear" so just tell where i am going wrong....

[edit]Add code tags. CR[/edit]
[ September 04, 2008: Message edited by: Campbell Ritchie ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
catch (IOException e)
{
}

This is a bad idea. How will you know if there are problems that prevent the program from running correctly?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that the first character in the filename seems to be a space or something. Not sure whether that could cause a problem.

Anyway, letting main throw the exception instead of catching and ignoring should give you the information that is needed to solve this problem.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the code button; you can see how much easier the code is to read now I have edited it.

Ulf and Ilja are both correct, I am sure. In fact if you had anything real in that catch (even simply "e.printStackTrace();"), you would know why your application isn't working by now.
 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks Ilja very much i did'nt notice that gap ya its working fine.....
now and also for your inspiring comments i love that......
I am sorry everybody for not declaring IOException in catch clause.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!