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
4
votes
1 answer

Why FileWriter doesn't create a new file?

Consider the following code: m_Writer = new PrintWriter(new FileWriter("LoginHistory.dat")); m_Writer.println(Integer.toString(s_NumOfLogins)); m_Writer.println(m_LoginHistoryStr); m_Writer.close(); Any ideas why I don't find any file…
JavaSa
  • 5,813
  • 16
  • 71
  • 121
3
votes
2 answers

How to avoid overwrite of existing file json object in node

I am trying to solve an issue where I am trying to write a json file with user input details. But each time I input new details it is overwriting the existing data. How can I avoid overwriting existing json object in a json file and add new object…
NoobCoder
  • 493
  • 8
  • 25
3
votes
5 answers

Java File object's renameTo method deletes my file instead of renaming it. Vistax64

Trying to take one mp3 file and rename it using a string variable. For example, I have a classical music folder, C:/classical, and I want a song called vivaldi renamed to FourSeasons. I want to find the absolute path of the initial file,…
3
votes
2 answers

Remove repeated content Java

I got this text, and I need to filter out these repeated lines and words. I don't know if there's a better way than what I'm doing. 00:00:00,413|03:50:25,600|ISDB|>> FALAM QUE A GENTE COMBINA 00:00:00,413|03:50:25,600|ISDB|PERFEITAMENTE.…
3
votes
3 answers

Counting (and writing) word frequencies for each line within text file

first time posting in stack - always found previous questions capable enough of solving my prob! Main problem I have is the logic... even a pseudo code answer would be great. I'm using python to read in data from each line of a text file, in the…
bhalsall
  • 35
  • 1
  • 6
3
votes
3 answers

Is java.io.FileWriter designed only for a single use?

I'm building a program that constantly writes to the same file, using java.io.FileWriter. During run-time, whenever I need to update the file, I call a method that writes "properly" and uses a class-level FileWriter. The problem starts on the second…
GalAbra
  • 5,048
  • 4
  • 23
  • 42
3
votes
0 answers

different ouputs using maven jar vs maven classes

I am working on a Project for my university in a group of 7 people. We have a Problem, that we have different outputs depending on what we use to compile one of our Components. If we use the .class files, which are also created by maven everything…
Julius K.
  • 33
  • 6
3
votes
4 answers

Convert file PATH to TreeUri (Storage Access Framework)

In my application of image gallery I use media content provider image to inflate recycler view . On long press on an image, I give user option to rename that image file. So I have complete file path (Ex:- /storage/sdcard1/DCIM/100ANDRO/ak.jpg )…
3
votes
1 answer

Writing an InputStream to a File in Java

I am writing this method which will convert an InputStream into a file, but the method is working for some of the inputs but not for all (when i pass a zip file as an InputStream it works). It simply creates a file with 0 bytes. I know that this…
tadddkldkl
  • 155
  • 2
  • 2
  • 8
3
votes
1 answer

FileWriter object reference not being overwritten as expected

I was working with a fellow peer on a simple coding exercise and we stumbled across this issue. The program requirements outlined that if the third command line argument was "a", the output file should be appended to, not replaced. So, he had code…
David Mordigal
  • 399
  • 3
  • 19
3
votes
3 answers

Java tabs ("\t") not working using FileWritter

As you can see, after every text comes a tab, everything is working fine, but after third tab (see output) it generates a space not a tab. fileWriter = new FileWriter(indexFile,…
Kefirchiks
  • 280
  • 4
  • 13
3
votes
1 answer

In java why does FileWriter throw IOException while FileOutputStream throw FileNotFoundException for the exact same reasons

From java docs public FileWriter(String fileName) throws IOException Throws: IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason and…
3
votes
1 answer

Android, .txt email attachment not sending via intent

I'm testing out creating a .txt file, and then sending it as an email attachment, via an intent. Creating the .txt File try { String fileName = "testFileName.txt"; File root = new File(Environment.getExternalStorageDirectory(),…
Birrel
  • 4,754
  • 6
  • 38
  • 74
3
votes
1 answer

ArrayList and BufferedReader Note Taking Program

I have created a simple program that takes a title and a note which you enter then you have a choice to export the notes to txt file using BufferedWriter however because each note is a object which is stored in a ArrayList when storing them I…
dijam
  • 658
  • 1
  • 9
  • 21
3
votes
1 answer

How to replace a specific line in a file using Java?

How do I write over a specific line in a text file using FileWriter and PrintWriter? I don't want to have to make a new file every time. Edit: Can I just cycle through the file, get the length of the String at the indicated line number, and then use…
Telle Miller
  • 43
  • 1
  • 1
  • 6