174 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
0
answers
37
views
Using NIO.2 to eventually delete a temporary file in Java [duplicate]
The legacy class File (singular) offers the deleteOnExit method to automatically delete a file later, when the JVM exits.
👉🏽 How to do the same in the modern NIO.2 classes?
The newer Files (plural) ...
3
votes
0
answers
50
views
Does `AsynchronousSocketChannel.write` and `read` methods apply a memory fence before calling the `CompletionHandler` methods?
When using AsynchronousSocketChannel.write to transmit a message,
class Transmitter(channel: AsynchronousSocketChannel) {
def transmit(bytes: Array[Byte])(onComplete: Consumer[String]): ...
1
vote
1
answer
709
views
Replace a file, if existing, or else create a new file, using NIO.2 in Java 7+
The Files.write & Files.writeString methods in Java 7+ are a concise handy way to write text to a file.
try
{
Files.write (
Paths.get ( "/Users/My_UserName/Example.txt" ) ...
1
vote
0
answers
222
views
Perform atomic move operation, but throw if target exist
How can I get the JDK to perform an atomic move operation, but throw FileAlreadyExistsException if the target already exist ?
My source and target are of type Path. I'm guaranteed that they both ...
peterh's user avatar
- 19.5k
0
votes
1
answer
75
views
NIO2 Path Symbols Java
If I created a two paths such as:
Path path3 = Paths.get("E:\\data");
Path path4 = Paths.get("E:\\user\\home");
And then make a new Path(relativePath) by using the ...
0
votes
1
answer
190
views
AsynchronousFileChannel not creating subdirectories
Below program throws "java.nio.file.NoSuchFileException" when subdirecties doesnot exist in path. Could some one please help how can I acheive this ? I want to insert records in asyncronous ...
1
vote
1
answer
2k
views
Non-blocking reading from the file using Reactor
Do you know if it's possible to create Flux of file lines really non-blocking way?
The best solution I've found is next:
Flux.using(
() -> Files.lines(PATH),
Flux::fromStream,
...
7
votes
3
answers
436
views
Thread-safety of NIO2 CompletionHandler
Is the following code thread-safe? If so, what guarantees the safe publication of the ByteBuffer instance to the thread executing the CompletionHandler?
AsynchronousSocketChannel channel = ...
...
2
votes
1
answer
2k
views
What is the actual difference between java Files.lines and Files.newBufferedReader().lines in Java?
Both two method will return stream of data, Is there any different between these two methods?
If it's Which way is more suitable to read the large files?
5
votes
0
answers
469
views
How AsynchronousSocketChannel maintain reading?
I need to connect to 4 machines and read data from sockets. I've chosen to use an async model of nio2.
Here is a pseudo-code :
class Connector {
private final AsynchronousChannelGroup group;
...
0
votes
1
answer
1k
views
Java NIO based scalable non blocking TCP client server design: recommend way to send large response back to client
I am trying to implement a highly scalable server in java for the following usecase
Client sends a request to server in a form of COMMAND PARAM
Server can send a varying size response, from a few ...
5
votes
0
answers
276
views
Support for case sensitive Windows directories in NIO.2
Recent Windows 10 builds feature an ability to mark a single NTFS directory (not the whole file system) as case sensitive, via fsutil.exe:
Per-directory case sensitivity and WSL
How to Enable Case ...
4
votes
2
answers
1k
views
Why does Path.relativize behave differently on Java 8 and Java 11?
Why does the method relativize behave differently on java-8 and java-11?
Path path1 = Paths.get("/a/./b/../image.png");
Path path2 = Paths.get("/a/file.txt");
Path path = path1....
0
votes
1
answer
632
views
Java Apache2 Log File Permission Denied
I'm trying to read the apache2 custom log files in the /var/log/apache2/my_site/access.log in a Java program. But i get a permission denied Excpetion.
The code is working on the Winows OS, i can read ...
2
votes
2
answers
662
views
Why is StandardOpenOption.DELETE_ON_CLOSE not deleting the source file of the FileChannel?
We have underneath method in Java which should delete the source file when its close method is called.
private void appendFile(Path destination, Path source) {
try (FileChannel sourceChannel = ...