760 questions
2
votes
1
answer
51
views
How to efficiently flush and write large amounts of data to a file using BufferedWriter in Java?
I'm working on a Java project where I need to write a large number of lines to a file. I know BufferedWriter can improve performance compared to writing character by character, but I am unsure about ...
2
votes
2
answers
78
views
BufferWriter still write in a file that doesn't exists anymore
I'm writing via BufferWriter to a file.
If I delete this file from the windows file system while the BufferWriter is still writing, the program doesn't report any error.
Where does the BufferWriter ...
2
votes
2
answers
119
views
Writing and returning a File in Kotlin using a buffer
I'm working on a function to process some data and output the results as a csv file. I am using a 'use' block to wrap the function and ensure all the resources are closed. the problem I am running ...
-4
votes
1
answer
65
views
Read complex CSV having custom delimiter and insert into database using PreparedStatement in java
I've googled around multiple options and still clueless on which is the best way to save data from csv file into database.
I tried using:
BufferedReader lineReader = new BufferedReader(new FileReader(&...
0
votes
0
answers
17
views
Beginner Java question on importing bufferedwriter in module-info.java
I am pretty new to java and I am trying to import some classes into my Java project, particularly java.sql and java.io.FileWriter + java.io.BufferedWriter
In my module-info.java, I have added the ...
1
vote
1
answer
84
views
From memory buffer to disk as fast as possible
I would like to present a scenario and discuss suitable design patterns to address it.
Consider a simple situation: a camera records to a memory buffer for ten seconds before stopping. Once recording ...
0
votes
2
answers
165
views
How to use try-catch (IOException) for BufferedWriter.write nested in if-else?
I have a block to write data(string) using BufferedWriter, but compiler keeps saying error: unreported exception IOException; must be caught or declared to be thrown this.dataContainer.stream()....
0
votes
1
answer
109
views
How to use BufferedReader and BufferedWriter to interact with a process's console using processBuilder
I have built a game of text based BlackJack and am coding a bot to play the game and record the results. I have successfully launched the game and read the initial data from the console however once ...
0
votes
0
answers
59
views
How to split a string in java when there is a new line character?
I'm trying to write a large String that I have into a txt file, in said string there are a lot of \n and I'd like that to register as a new line in my txt file. I've tried to split the string whenever ...
0
votes
0
answers
134
views
Python os.fdopen() gives OSError: [Errno 9] Bad file descriptor
I am trying to test out a virtual serial connection in python with individual funtions for each test.
'''
Testing Virtual Serial Port Connections
'''
import os
import sys
import time
import serial
...
0
votes
2
answers
170
views
Why won't my client nor server send messages to each other?
For my networking course, I am tasked with turning a OneWayMesg (Client sends messages to Server) program to a TwoWayMesg (Client sends messages to Server and Server sends messages to Client).
In ...
0
votes
1
answer
133
views
Why my code showing error: unreported exception IOException; must be caught or declared to be thrown at bw.write(s); [duplicate]
Problem Statement: Given an array of integers, answer queries of the form: [i, j] : Print the sum of array elements from A[i] to A[j], both inclusive
This is the code I used:
import java.io.*;
import ...
0
votes
0
answers
35
views
Can I write only in certain lines in a file with BufferdWriter without overwrite others?
I want to save a highscore in a database, but if an sql-exeption is thrown I want to temporary save the data in a file. The game has diffent modes and for each there is a highscore. I would like to ...
1
vote
1
answer
1k
views
Passing a BufWriter to a function in Rust
In this example I'm trying to pass a BufWriter to some functions but don't understand generic type syntax enough to figure out whats missing.
Instead of passing the file, I want to pass the buffered ...
0
votes
1
answer
181
views
How can I write to a file using BufferedWriter if the input type is double?
I am trying to write to a file using BufferedWriter. As the write method takes int argument, I am casting input of double type into int type but it is not being written properly into the file.
try{
...
0
votes
1
answer
87
views
BufferedWriter with no UTF-8 support
I'm trying to make BufferedWriter write into txt file in format "latin - cyrillyc",and cyrillyc part is not working(hieroglyphs instead of text),neither do special symbols like ą ł ó ę etc.
...
0
votes
1
answer
363
views
Java BufferedWriter not creating text file when file doesn't exist
So I'm trying to use the BufferedWriter Class to create and write to a text file. However, a file is never created, nor is any error generater. However, if I create a text file and specify its path, ...
0
votes
1
answer
670
views
Java write escaped characters into file
I'm writing to a file and I need to escape some characters like a quotation mark.
File fout = new File("output.txt");
try (FileOutputStream fos = new FileOutputStream(fout); BufferedWriter ...
0
votes
0
answers
89
views
Closing a Stream after instantiating a bufferedWriter
Just wondering if my bufferedWrites will work outside this try clause as it should as. i atm have no way of checking the outcome atm but. As in i only need the stream to be open for the instantiation ...
0
votes
0
answers
43
views
Java Buffered writer and file writer not writing to file
I am experimenting with java by building a commandline game. I want to save user progress to a file , and am using buffered writer as shown below but it does not write to file.What might be the issue?
...
0
votes
0
answers
99
views
BufferedWriter and map function: empty files
I am trying to write a huge output file the quickest possible on two different files.
I have created my lists list1 and list2, and I am now trying to write those in a respective file.
I started to ...
-2
votes
2
answers
211
views
How to use try-with-resources in nested function in java? [duplicate]
I noticed that if I don't call myBufferedWriter.close(), my content will not appear in the target file. What if the program ends accidentally before reaching myBufferedWriter.close()? How to avoid ...
0
votes
1
answer
435
views
How to stop BufferedWriter to assigning null value every time the method has been called?
I am working on a game and I want to store the High score in a file and read it whenever it's needed. I wanted to use BufferedWriter and BufferedReader like this on the gameover class.
File fi ...
1
vote
0
answers
32
views
Why is my Java program creating a new file every time I call append? [duplicate]
I am new to file handling in Java. My input file is a csv file with a number of columns. My objective is to create a new file each time I encounter a different value in the input .csv file and append ...
0
votes
1
answer
180
views
How do you get BufferedWriter to remove brackets from an ArrayList when writing to a file?
I have made a bufferedWriter to take an arraylist of things and comma separate them. It works well, but when I retrieve the data it starts adding extra brackets: [banana, potato, tomato, carrot] goes ...
1
vote
1
answer
48
views
Write to File doesn't persist between activities
I'm writing and reading from a file and it works perfectly fine. However when the activity is switched or the app is closed it appears that the file is deleted or some such as null is returned when ...
1
vote
1
answer
1k
views
Why BufferedWriter is writing the data into the file partially? [duplicate]
I am trying to write a json file using this code:
File f = new File("words_3.json");
if (!f.exists()) {
f.createNewFile();
}
if (fileWriter == ...
0
votes
1
answer
407
views
How do make a login function using BufferedReader?
I am a first-year programming student and I was tasked to make a Login and Register program using Java Swing (Application Window) and BufferedReader+Writer. I am now able to write a username and ...
0
votes
2
answers
342
views
how to select data in txt file and print into different txt file java
I have a txt file called employees.txt which contain employee id and names. Their id starts with either 18,19 or 20. And have to look within the file if the line starts with 18 it needs to go to ...
-2
votes
1
answer
57
views
BufferedWriter not writing data line by line
Currently trying to edit my old code from System.out.println() statements that display the results of a benchmark test to writing the results to 2 different .txt files. I am doing this so I can create ...
0
votes
2
answers
446
views
Creating a Simple Java Webserver. Image is not showing up
I'm currently in (1st year) college and was assigned to do Java Server. Currently, I have created a really simple HTML page (Hello world style) and text shows up in the Localhost. However, when I ...
0
votes
1
answer
658
views
Trying to read multiple lines from a one text file then print out results to new text file java
I created this program where it takes an input from one text file where students grades and names are recorded like this:
lastName:firstName:Test1:Test2:Test3
After this the program reads them and ...
0
votes
1
answer
121
views
External Merge Sort with limited space
so my task is to make an external merge sort with a text file.
I'm also supposed to only have a maximum of 3 Strings at one time.
This is what my merge-Method looks like:
public static void ...
1
vote
1
answer
63
views
Why is the Scanner object affecting the BufferedWriter's ability to write to a file?
I'm trying to read the text contents off of a given URL, then print the contents, as well as write it to a text file using BufferedWriter. I need to include a code block that allows only 35 lines of ...
0
votes
1
answer
468
views
Read string received from JavaScript WebSocket using Java InputStreamReader
I am trying to read value received from JavaScript WebSocket using Java
I have this JavaScript code:
const socket = new WebSocket("wss://localhost:7999"); // start
socket.addEventListener(&...
0
votes
1
answer
771
views
Java bufferedreader not reading file
I have a method called "add" which takes a string as an argument and uses the bufferedwriter to write it to the file. Once this is done, the bufferedwriter is flushed.
In another method &...
1
vote
1
answer
86
views
BufferedWriter does not detect read only directory
I have a java application that reads and writes csv files. I have created a read only directory on my Mac that my application will try to write a csv file to. I did this with chmod 000. No file gets ...
0
votes
2
answers
154
views
My File Clears Everytime I Run My Code - Java
I have Server-Client messenger - not important - and I have a settings file to store the settings, but for some reason when I run the code, the settings file clears.
Here is the code that makes the ...
0
votes
0
answers
35
views
My Server-Client Messenger Doesn't Seem To Be Sending/Recieving Messages - Java
I have made tried to make a client server messenger using sockets, but it seems to not be sending/recieving messages. I am using a BufferedWriter and BufferedReader if that helps at all. Everytime I ...
0
votes
0
answers
104
views
How do I access a variable from another thread
I am trying to make an action listener for a button to send a message from a server to client and vice versa, but I can't access the bufferedwriter variable from the thread, so I can't send a message. ...
-1
votes
1
answer
254
views
How to write a converted to byte array text file content into another one in java
I converted a text file content to a byte array. I want to rewrite it into another text file but BufferedWriter writes it all in one line how can I fix it? I want that to be exactly like its original
...
0
votes
1
answer
652
views
How to create file only if there is data in BufferedReader?
I am receiving data from a stream and writing the result to a file
File resultFile = new File("/home/user/result.log");
BufferedWriter bw = new BufferedWriter(new FileWriter(resultFile));
...
0
votes
1
answer
789
views
CSVPrinter not printing to Zip
I have a method where I save all data by packing together images and annotations in csv format associated with them. I use CSVPrinter to print to the CSV which I'm trying to append to the zip file, ...
0
votes
1
answer
114
views
BufferedWriter is not writing contents of Map to text file; Minecraft server
I have PVPStats objects stored in PlayerMeta.java:
public static Map <UUID, PVPstats> sPVPStats = new HashMap<>();
I know for sure the map is getting populated with objects that contain ...
1
vote
1
answer
2k
views
Buffer and File in Java
I'm new to java and I want to ask what's the difference between using FileReader-FileWriter and using BufferedReader-BufferedWriter. Except of speed is there any other reason to use Buffered?
In a ...
0
votes
2
answers
1k
views
Rollback or Reset a BufferedWriter
A logic that handles the rollback of a write to a file is this possible?
From my understanding a BufferWriter only writes when a .close() or .flush() is invoked.
I would like to know is it possible to,...
0
votes
1
answer
601
views
Handling rollback using BufferWriter in Spring Batch Applications
In my use case, i would like to use a buffer writer to handle the storing of strings.
Only when the commit interval has been met, it will flush the writes
This is to ensure that when there is a ...
0
votes
1
answer
129
views
How to write into a file without overriding the current content while limiting the file size in Java
Im using this code in order to write some text to a file, while limiting the size of the file to 1G
but every time a new text is entered, its overriding the current file content.
How do I disable the ...
0
votes
1
answer
143
views
Printing an ArrayList using buffered writer in JFrame Form (Java)
I have these three methods and I am trying to write the contents of three lists to a file using the buffered writer.
First Method: To Save File:
public static String showSaveDialog()
{
...
-4
votes
1
answer
158
views
What is the getResourceAsStream() used only for reding inputs, how to write outputs [closed]
So basically I have a file that the java code reads from and writes to.
BufferedReader works
BufferedReader bReader = new BufferedReader(
new InputStreamReader(
...