Questions tagged [filewriter]

Java built-in class that allows writing character files.

Public class FileWriter extends OutputStreamWriter.

Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.

Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

Since: JDK1.1

Source: Oracle

1133 questions
3
votes
4 answers

what are the concern regarding simultaneous read and write to a file?

consider the following scenario: Process 1 (Writer) continuously appends a line to a file ( sharedFile.txt ) Process 2 (Reader) continuously reads a line from sharedFile.txt my questions are: In java is it possible that : Reader process somehow…
nafas
  • 5,283
  • 3
  • 29
  • 57
3
votes
3 answers

Java I/O: How to append to an already existing text file

Hi I am having no problem writing to or appending to a file, the only problem is that as soon as I quit the program and then run it again, it creates a new file overwriting my original file. This is a problem, as I am using the text file to keep a…
joepour
  • 6,831
  • 10
  • 32
  • 29
3
votes
2 answers

Java Synchronize filewrite

I have many threads that writes to a pool of files, I want to synchronize filewriter to avoid a dirty append. Firstly I thought about this: public synchronized void write(Ing ing) { File file=getFile(ing); FileWriter writer; writer=new…
Tobia
  • 9,165
  • 28
  • 114
  • 219
3
votes
8 answers

In .Net using File.CreateText() also locks file, why?

I was using the CreateText method to create an empty file (as below) in "App1". Then tried to have another application write to that file but it failed b/c it was locked. It was not unlocked until I closed "App1" File.CreateText(path) To fix this…
Gern Blanston
  • 42,482
  • 19
  • 50
  • 64
3
votes
2 answers

Why is BufferedWriter not writing to file?

I have this code: String[] strings = {"Hi" , "You", "He", "They", "Tetrabenzene", "Caaorine", "Calorine"}; File file = new File("G:\\words.txt"); FileWriter fWriter; BufferedWriter bWriter; try { if((file.exists())) { …
user3210944
  • 57
  • 1
  • 6
3
votes
3 answers

Java. Appending string to file, ended with strange output

I have the following simple function to append text to some txt file. The length of the text in the code is 1024: void AppendToFile(String filename) { String text =…
Gari BN
  • 1,635
  • 2
  • 17
  • 31
3
votes
1 answer

Puzzle with FileWriter in Groovy

I have Groovy code like this... class GuiWindow extends SwingBuilder { .... FileWriter writer GuiWindow(def controller) { .... writer = new FileWriter("DATA${new Date().time.toString()}.txt") writer.write("Count, Rate\n") This…
adrianmcmenamin
  • 1,081
  • 1
  • 15
  • 44
3
votes
5 answers

Simpler way to write a java output to both console and text file?

So im a pretty big noob at java and I have a exam coming up and have been practicing all week. My progress has been slow but steady. One exercise I am doing requires me to print the output of an array calculation to a console AND create a file…
DarkD
  • 39
  • 1
  • 2
  • 6
3
votes
1 answer

Using the FileWriter with a full path

I specified the full path of the file location when I created a FileWriter, but I did not see the file being created. I also did not get any error during file creation. Here's a snippet of my code: public void writeToFile(String fullpath, String…
chris yo
  • 1,187
  • 4
  • 13
  • 30
3
votes
3 answers

Using FileWriter and BufferedWriter clearing file for some reason?

For some reason, when I create a new BufferedWriter and FileWriter in my program (Even if I haven't used it to write anything yet), it clears the file I have selected of all it's text. selectedFile is determined by a JFileChooser. public static File…
None None
  • 147
  • 2
  • 3
  • 11
3
votes
4 answers

FileWriter writing extra nulls at end of file

For large strings (60MB or so long), FileWriter is appending extra nulls to the end of my files. For small strings this code works as expected. For clarity, dat and filePath are Strings. FileWriter fstream = new FileWriter( filePath…
Chad Mourning
  • 608
  • 2
  • 12
  • 25
3
votes
1 answer

scan.hasNext false when it should be true

So I'm a beginner at programming and I'm trying to figure out what the problem is with the following functions. The problem is with the scan.hasNext() method I have two println statements (one right after I make scan, and one on the second method)…
Luis Cruz
  • 29
  • 3
3
votes
2 answers

What "cscript //NoLogo" stands for?

This is a java program code that runs the Notepad program and pastes a specific text stored in this program itself.... I was wondering if you can explain me the String vbs value, and also the File file, and the ("cscript //NoLogo " + file.getPath())…
Sarsur.A
  • 295
  • 1
  • 4
  • 7
3
votes
2 answers

JAVA IO - please clarify

I am a newbie and I really want to learn the concept instead of just copying and pasting code. I wanted to learn how exactly to use the Jave IO and was confused and disapointed to see so my different versions of code. So I made my own notes and…
user547453
  • 1,035
  • 6
  • 22
  • 38
2
votes
1 answer

phonegap - where is the file saved?

I'm want to save an file with text in my phonegap app. I'm using the exaple code from phonegap - FileWriter_full_example. Where is the file readme.txt located after writing? When I'm seraching after 'renamed.txt' at the windows explorer i get an…
David
  • 4,027
  • 10
  • 50
  • 102