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

How to append the contents to the file at the beginning using Java?

I have used Filewriter class. But it will append at the end of the file. Can anyone tell me the method to append the contents to the file at the beginning without overwriting.
2
votes
2 answers

Why is my first .nextline in the loop skipped then not skipped the next time around? and how do I stop it from overwriting?

I needed to create a basic program to input text to a .txt document so I created this but I don't see why the first question is skipped when the program is first run. It doesn't happen if the first question that sets the loop isn't there. Also how…
2
votes
1 answer

Assigning a custom icon to a Mac desktop element

I am writing an application in Swing that involves creating an Internet shortcut on the desktop for a particular site. It works fine in Windows. Mac allows me to create the shortcut, but does not allow me to assign it my custom icon. How can I…
Aqui98
  • 21
  • 2
2
votes
2 answers

write one big file or multiple small files

I'm wondering what is better in therms of performance: write in one big text file (something about 10GB or more) or use a subfolder system that will have 3 levels with 256 folders in each one, the last level will be the text file. Example: 1 1 2 …
Frederico Schardong
  • 1,946
  • 6
  • 38
  • 62
2
votes
1 answer

Some CSV cells are wrapped in "quotes" while others are not

I am a newbie to Python. I am not able to debug the code. Can someone please guide how to debug? with open(inputFile, mode='rt') as f: reader = csv.reader(f, delimiter=',', quotechar='"') header = next(reader,None) rows = sorted(reader,…
user3093845
  • 43
  • 13
2
votes
1 answer

How is there no flush in FileReader, but there is for FileWriter?

Say I try to run this code: FileWriter fw = new FileWriter("a.txt"); fw.write("A"); It wouldn't work as data is buffered and won't be auto flushed until it reaches max buffer size. So we flush manually with fw.flush();, after which this would…
Stefan
  • 969
  • 6
  • 9
2
votes
4 answers

Writing data to a .CSV file using a Java 8 Stream

I am trying to output 2 collections of data to a .csv file in Java. Collection 1 = customer names Collection 2 = customer references I want the .csv to present as: Smith:839393, Johnson:283940, Collins:293845 My code: private void writeDataToFile()…
Steerpike
  • 1,712
  • 6
  • 38
  • 71
2
votes
1 answer

Executable Jar file can't read internal JSON file

I have an application with a read-write script that will read and write a set of links and checkboxes and either read or write a JSON file. Every part of the application works fine except when I try to read a JSON file. I've tried using both…
Tyler Moen
  • 81
  • 5
2
votes
2 answers

How to always write out to a .csv data file in a Jenkins Groovy pipeline even with test failures

I have a test to generate new customer data using TestNG: public class GenerateNewCustomers{ private static ArrayList customers = new ArrayList<>(); @Test(invocationCount = 5) public void runApplicationGeneration() throws…
Steerpike
  • 1,712
  • 6
  • 38
  • 71
2
votes
2 answers

Create json file from SQL Table, then be able to query the file

I am trying to accomplish the following (using Netbeans 11.3): 1.) Get Data (String) From a Column in an SQL Table. 2.) Convert and save the Data as a JSONArray using Filewriter. 3.) Query the newly created JSON file (output.json) so the data can be…
jdk25
  • 23
  • 5
2
votes
3 answers

How to write or store string array in .txt file in java

I want to write string array in .txt file. But after running my code, I am getting an empty file. Here is my code. public void DataSave() throws IOException { File fout = new File("Data.txt"); FileOutputStream fos = new…
Ferdousi
  • 319
  • 5
  • 17
2
votes
1 answer

Fibonacci in Java using Dynamic Programming and Recursions

I'm new to Dynamic Programming so I tried to create a file and write it onto Array.txt in the download section. The logic is: If the Array is longer than the current array: Extend the array and copy to old array onto the new one I, however, can't…
dizmac
  • 99
  • 9
2
votes
1 answer

Files.readAllLine() not working after FileWriting

hoping you're doing well, this is my first question I have a trouble: My goal is to create java files from pieces of code (fields, attributes, constructor) I tried to do this by altering between reading and writing file. Reading file to get the…
NASSIM ADRAO
  • 145
  • 1
  • 9
2
votes
2 answers

Java FileWriter class - java.io.FileNotFoundException: * no such file or directory -Ubuntu

I am using this method to generate some turtle files .ttl in a sub-directory of my project: public static void write(int id, int depth){ try { FileWriter fw = null; switch (getName()){ case ("KG1"): …
Betty
  • 237
  • 6
  • 16
2
votes
2 answers

Java - Naming a file in FileWriter using Scanner

How do I name a file using Scanner? For some reason, Java's FileWriter won't accept a pre-defined String as an input. The code below is simplified to what I mean : ` import java.io.*; public class Example{ public static void main(String[] arg)…