473,394 Members | 2,160 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,394 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 2655
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.