473,325 Members | 2,442 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,325 software developers and data experts.

File, FileWriter, BufferedWriter....LOST

momotaro
357 100+
Hi everybody !

I want to create a File then write to it so here is what I use:
Expand|Select|Wrap|Line Numbers
  1. public File creatFile(String name)
  2.     {
  3.         File file = new File(name);
  4.         try {
  5.             file.createNewFile();
  6.         } catch (Exception e) {
  7.             System.out.println("file" + name + "not created");
  8.         }
  9.         return file;
  10.     }
  11.  
  12.     public void writeToFile(File file, String text)
  13.     {
  14.         try {
  15.             fstream = new FileWriter(file, false);
  16.             BufferedWriter bufferedFile = new BufferedWriter(fstream);
  17.             bufferedFile.write(text);
  18.         } catch (Exception e) {
  19.             System.err.println("can not write to" + file.getName());
  20.         } 
  21.     }
the files are created but can't be written using my method...??

here is how I use them:
Expand|Select|Wrap|Line Numbers
  1. FileFactory f = new FileFactory();
  2.         for(int i = 0; i < 3; i++)
  3.         {
  4.             File file = f.creatFile("text" + i + ".txt");
  5.             f.writeToFile(file, "Hello World!");
  6.         }
Jul 31 '11 #1
1 2650
momotaro
357 100+
never mind I forgot the .close();
Jul 31 '11 #2

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

Similar topics

5
by: Dave W | last post by:
Hi, I'm hoping for some guideance. I'm trying append to the bottom of a text file using Java. Any advice, further reading would be greatly appreciated! Cheers, Dave
29
by: jacob navia | last post by:
A signed int can contain up to 2Gig, 2 147 483 648, to be exact. Since The Mars rovers landed, I have been storing the photographs in two directories, Spirit and Opportunity. I had more than 18...
8
by: Peter | last post by:
I'm trying to write a proceedure that will delete a file completely off a hardrive. I just don't want to kill the file. I want to rewrite over the data with 1's and 0's 8 times. Anyone have an...
4
by: Petr Vileta | last post by:
Sorry if my question was be here earlier, I'm new here ;-) I have html form where is the tag <input id="x" type="file" name="upload"> and another fields. After submit script on server take some...
12
by: lalou89 | last post by:
Develop a simple text editor program. The program will show the user a menu of choices and will act according to his choice. Use functional decomposition to break the system into small functions that...
0
by: =?Utf-8?B?S29vcyBC?= | last post by:
I used FTW to collect Files & Settings from old computer. Flash drive used as medium. Found to my horror that USMT.unc contains .dat file only. How can I put togehter or simulate status file?...
6
by: topala1984 | last post by:
hello all excuse my english, I`m a beginer in java and I want to remove duplicate cities + rearrenging file`s lines elements from one 150 mb file, in my file I have that: ...
6
by: carlos123 | last post by:
Ok guys, check this out! Im getting an error "Error: Index: 0, Size: 0" not sure why. try{ // Create file FileWriter fstream = new FileWriter("database.txt"); BufferedWriter...
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
How would I load a file from a resource? We have a 'PDF-like' file that is formatted for printing the our label forms (it isn't quite like a PDF, but pretty close. It lets us enter text that...
3
by: Jerry Spence1 | last post by:
I have a project that has these files: frmCD.resx frmCD.Designer.vb frmCD.vb I had a virus which wiped out the frmCD.vb. Is it possible to regenerate it from the other files? -Jerry
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.