Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Not able to write the output to the file.

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;

public class FileIo {

public static void main(String args[]) {
try {
File f=new File("Testdir");
f.mkdir();
File subf=new File(f,"Subdir");
subf.mkdir();
File fsubf=new File(subf,"SsubDir");
fsubf.mkdir();
File newf= new File(f,"a.txt");
newf.createNewFile();
FileWriter fw=new FileWriter(newf);
BufferedWriter bw=new BufferedWriter(fw);
bw.write("SCJP");
bw.flush();
bw.close();

} catch(IOException e)
{
System.out.println(e);
}
}
}




Here is my Code , I am not able to Write into the file. Please Help me.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We need you to help us help you by UseCodeTags and TellTheDetails.
What response from the program do you get, and what did you expect?
 
Soumya Ranjan Mohanty
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to write using BufferedWriter in my file a.txt. As in the above example the word SCJP in my file a.txt under directory TestDir,
 
Sheriff
Posts: 22572
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I shall repeat:

Jonas Isberg wrote:TellTheDetails.
What response from the program do you get

 
Soumya Ranjan Mohanty
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i get an output where nothing written to the file.. I want something to be written in the file a.txt
 
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


try this it will work.

regards
Raza.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic