Skip to main content
3 votes
1 answer
115 views

How to efficiently split a text file with an arbitrary Charset without damaging code points?

Given a valid text file file and its java.nio.charset.Charset how can I efficiently (preferably using RandomAccessFile.seek() or InputStream.skip(), without reading the whole file) split it into two ...
Basilevs's user avatar
  • 24.6k
1 vote
0 answers
54 views

No Support for "Don't Fragment" Bit in Datagram Channels in Java NIO

I'm currently working with Java NIO and facing a challenge with Datagram channels. I need to set the "Don't Fragment" bit for UDP packets, but I've discovered that there’s no option ...
Harshal Goyal's user avatar
0 votes
2 answers
73 views

Does StandardOpenOption.APPEND require StandardOpenOption.WRITE?

According to the documentation, StandardOpenOption.APPEND seems it requires the StandardOpenOption.WRITE. If the file is opened for WRITE access then bytes will be written to the end of the file ...
Jin Kwon's user avatar
  • 22.3k
6 votes
3 answers
411 views

How to know if the filesystem supports sparse file programmatically

Java NIO provides us the option to create sparse files val path = Path("""E:\a""") val fileChannel = FileChannel.open( path, StandardOpenOption....
Cyber Avater's user avatar
  • 2,106
0 votes
0 answers
104 views

Configuring Java NIO Channels for IPv4 and IPv6 Separately

I've been looking into Java NIO channels for a project, specifically aiming to open sockets for both IPv4 and IPv6 configurations separately. While DatagramChannel provides an option to specify the IP ...
Harshal Goyal's user avatar
1 vote
0 answers
94 views

Java NIO DatagramChannel: Unable to Open Multiple Sockets on Same Port with IPv4 and IPv6

Hello Stack Overflow community, I'm encountering an issue while working on a project involving Java NIO Datagram Channels. My goal is to open two sockets on the same port, one using IPv4 and the other ...
Harshal Goyal's user avatar
0 votes
1 answer
62 views

What is the minimum number of written bytes of a SocketChannel when its key is writable?

Let's say we're going to write some bytes to a SocketChannel within a writable SelectionKey. // in a single selection loop if (selectedKey.isWritable()) { final var channel = (SocketChannel) ...
Jin Kwon's user avatar
  • 22.3k
0 votes
1 answer
212 views

how to create absolute path from absolute and relative one?

I write a simple application on kotlin and I encountered the next problem: I have relative (../../) and absolute (a/b/c) paths. I want to get path a/ . How to accomplish that without dancing with ...
Nikolai's user avatar
  • 39
0 votes
1 answer
402 views

Java NIO: How can I read into a buffer possibly multiple times?

I am working on a Java project. I have the following code that is part of the Selector's while loop. The response is supposed to be less than 256 and it ends with a line break. But as far as I ...
sleekster's user avatar
3 votes
2 answers
439 views

Only copy a file after it is being done written to

I have a non-Java program writing files to a directory. My Java program then copies these files to a different directory. Is there a way for Java to check if the last file is fully written to before ...
MKRabbit's user avatar
0 votes
2 answers
163 views

How to check content-length match after download image in java Nio?

static void downloadWebp(String url) { URL url1; try { url1 = new URL(url); } catch (MalformedURLException e) { throw new RuntimeException(e); } ...
djy's user avatar
  • 767
1 vote
1 answer
565 views

java: rename file and add suffix if it already exists

I need to rename a file. Path destPath = Paths.get(directoryPath, hash); Files.move(path, destPath); The problem is that when I'm trying to "rename" the file, it can already exist. Is there ...
Jordi's user avatar
  • 23.6k
0 votes
0 answers
59 views

java io: Create file name directly with its digest code

Currently, my code snippet: Path destinationFilepath = Paths.get("/tmp/a/b/c/" + UUID.randomUUID().toString()); FileUtils.createParentDirectories(path.toFile()); destinationFilepath = Files....
Jordi's user avatar
  • 23.6k
4 votes
3 answers
2k views

Java InputStream: copy to and calculate hash at the same time

Here are my two code snippets: public class Uploader { private static final String SHA_256 = "SHA-256"; public String getFileSHA2Checksum(InputStream fis) throws IOException { try {...
Jordi's user avatar
  • 23.6k
0 votes
0 answers
3k views

Java download video from a given URL

I need to download a video in the given link and save to my local directory. This is the code I used for that. And I'm using java nio package. public void usingNio() throws Exception { ...
Anjula Samarasinghe's user avatar

15 30 50 per page