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

Java FileReader and Writing

Im struggling to get my head around saving an array to a file and then reading it back in to the same array that it was saved from. the code for Person is import java.io.*; public class Person implements Serializable { protected…
-2
votes
2 answers

Overwriting a text file when i don't want it to. - Java

I am working on a log file that is currently over-writing itself every single time. Now The thing is all i want it to do is to just write on the first line and append the list below to show the history from newest to oldest. Problem is I am not sure…
M1M N7
  • 69
  • 2
  • 7
-3
votes
1 answer

Code inside for loop wont write to a text file

When I run my program, it writes the elements outside of the for loop into the file however the contents in the for loop are not written to the file. public static void main(String[] args) { PrintWriter out; try { out = new…
-3
votes
1 answer

While loop not incrementing java

i'm just starting to learn about java. My while loop does not seem to increment. Here's the snippet of my while loop inside a try and catch: File file = new File("Reservation.txt"); Scanner sc = new Scanner(file); sc.useDelimiter(","); try { …
-3
votes
1 answer

why I can't add my answer to readwrite.txt.?

I try to add my answer to readwrite.txt, but I don't find my answer every time I run the code. public static void main(String[] args) { ArrayList category1=new ArrayList<>(); category1.add("die…
-3
votes
2 answers

copy from existing file to another file using buffer

copy_file.java package IOstream; import java.io.*; import java.nio.Buffer; public class copy_file { public static void main(String[] args) { String str = ""; File f1 = new File("first.txt"); File f2 = new…
disha
  • 3
  • 5
-3
votes
2 answers

BufferedWriter outputting strange characters when saved to new file

I'm using the following code to process a large text file, line by line. The problem is that I'm using a language other than English, Croatian to be precise. Many of the characters appear as � in the output file. How can I resolve this? The file is…
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153
-3
votes
1 answer

How do I end line when writing to a text file?

I'm writing to a text file but when I look into the file everything is in on line even though I'm adding "\n" in the string in the for-loop. What am I overlooking? File file = new File(dir.getAbsolutePath() +…
biz
  • 53
  • 6
-3
votes
2 answers

Writer not writing anything to file

public class AddDetails extends Application { private final String FileName = "C:\\Users\\marsh\\OneDrive\\Documents\\CustomPrograms\\CalcProb\\Players.txt"; private String Name; private char Hand1, Hand1; private double Skill1,…
-3
votes
1 answer

Don't know how to handle FileWriter exceptions

In my code, one of my methods says: this.write("stuff") and the write method is public void write(String text) throws IOException { FileWriter writer = new FileWriter(path, true); PrintWriter printer = new PrintWriter(writer); …
Andriy F.
  • 15
  • 1
  • 2
-3
votes
6 answers

Write to a file without overwriting the existing data within that file

I have a filewriter that takes String data from the user and writes it on the file. But the filewriter replaces the already existing data in that file. How do I prevent it from doing it? I just want to keep adding information without writing over…
Kharbora
  • 85
  • 1
  • 2
  • 10
-3
votes
1 answer

How to write on the second line in a .txt file (java)

I want to write a few arguments in a .txt file and I want to sort them. To do that I want to go to the next line for every groop of arguments but I dont know how to do that.I have tried the: x.nextLine(); statement, but that is only for scanning…
codermaster
  • 156
  • 11
-4
votes
1 answer

Write to console using Filewriter in java

I got problem in java. I need to use FileWriter to write output. But now i want to use Filewriter to write standard output( to console). Have any ideas?? Thanks for your helping
Duc
  • 29
  • 6
-4
votes
1 answer

Writing to a file in loop doesn't work

I want to open a file, write it in a loop (append everything to the previous lines) and then close it. I had already implmented everything in a single method inside the loop and I had a problem similar to this question. So, I'm trying to implement…
user1419243
  • 1,655
  • 3
  • 19
  • 33
-4
votes
1 answer

why do i ever need to use .close() on resources

i know this may get a down vote this is bothering me a lot i have already read all posts on .close() method like explain the close() method in Java in Layman's terms Why do I need to call a close() or shutdown() method? the usage of close()…
manifold
  • 437
  • 6
  • 23
1 2 3
75
76