Questions tagged [filechannel]

In Java FileChannel is an abstract class for reading, writing, mapping, and manipulating a file

In Java FileChannel is an abstract class for reading, writing, mapping, and manipulating a file.

A file channel is a SeekableByteChannel that is connected to a file.

It has a current position within its file which can be both queried and modified.

The file itself contains a variable-length sequence of bytes that can be read and written and whose current size can be queried.

The size of the file increases when bytes are written beyond its current size; the size of the file decreases when it is truncated.

The file may also have some associated metadata such as access permissions, content type, and last-modification time; this class does not define methods for metadata access.

More info

193 questions
0
votes
1 answer

Getting OverlappingFileLockException when locking file channel in Java

Here's the part of the code that is problematic: FileChannel fileChannel = FileChannel.open(filePath, StandardOpenOption.WRITE); fileChannel.force(true); FileLock lock =…
A6SE
  • 177
  • 1
  • 11
0
votes
0 answers

Obtaining the file key of an already-open file channel

Is there a way to obtain the file attributes (specifically, the file key) of an already-open file channel? This operation would be similar to the POSIX fstat function. If I know a path of the file, I can call Files.readAttributes(…), but this still…
Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
0
votes
1 answer

java.io.InputStream#available() method equivalent in nio package

The class FileInputStream has a method available() that returns the remainging size to be consumed I'm trying to convert a program that uses FileInputStream to use FileChannel, I konw that we can consume the FileChannel using a ByteBuffer, but what…
octopus
  • 13
  • 3
0
votes
1 answer

Multithreaded access to files in Java

I'm working on a multithreaded server in Java. The server monitors a directory of files. Clients can ask the server: to download a file from the server directory to upload a new version of an already existing file to the server, overwriting the old…
PoriPiriPuri
  • 43
  • 1
  • 4
0
votes
1 answer

Android - Using Filechannel to copy file at sd card isn't possible?

I made this method to copy file from inputpath to outputpath. It works when input is located in sdcard, and output is located in local storage, But when I change output to a file located in sdcard, it doesn't work and doesn't show any error. How can…
0
votes
2 answers

Is FileChannel.position() thread safe?

Is it safe to write from different threads to one file using FileChannel.position()? This is necessary for multipart downloading. Each thread will write to its position in the file, i.e. the positions of the thread will not intersect.
proninyaroslav
  • 720
  • 2
  • 7
  • 19
0
votes
2 answers

Copy image from one folder to another - Android

Hi Everyone I am trying to copy an image from one folder to another which user selects from the gallery. It's not throwing any error as well. Please check the below code. protected void onActivityResult(int requestCode, int resultCode, Intent…
Mac_Play
  • 302
  • 4
  • 21
0
votes
1 answer

ObjectInputStream throws ioexception inside the filelock lock section

I have a function, that has to put key value pair into map stored in file. If file does not exist, I have to create it. I try to lock the file, when I work with it with Filelock lock(). But when I try to write into it( Inside of the locked section),…
neverEugene
  • 69
  • 10
0
votes
1 answer

Java insert bytes to file at given position without overwriting any data

I have a List backed by (among other things) a FileChannel (of a relatively large file), enabling random reads to objects. The implementations of get(), size(), and add() were fairly straightforward. However, any remove() and set() calls are…
MeetTitan
  • 3,383
  • 1
  • 13
  • 26
0
votes
0 answers

Memory is not released while using MappedByteBuffer

I am trying to read one big file in chunk . So the read operation will be called multiple times being offset one of the parameter . The read is working perfectly fine . But the real problem is starts when I try to delete the file after read is…
0
votes
1 answer

Reading and writing file in number of Byte Buffer chunks of smaller length

I am trying to read file in ByteBuffer chunks of fixed length and then store it to a list of ByteBuffer and then after some operations read those ByteBuffer chunks in a sequential order to reconstruct the file. Problem is that while writing output…
andi99
  • 117
  • 3
  • 8
0
votes
1 answer

i want java stream channel like filewriter

i just want fileoutputstream like filewriter at same style like this //filewriter code try { File file = ('some file link'); fw=new FileWriter(file,true); fw.write("2017-06-08"); fw.write("#");//separator …
LocketGoma
  • 75
  • 1
  • 2
  • 11
0
votes
1 answer

java.nio.channels.AsynchronousClose Exception on Java 8

I just moved my code from java 7 windows to java 1.8 Linux and i am getting this stack trace on same code base java.nio.channels.AsynchronousCloseException at…
Aravind R
  • 716
  • 1
  • 10
  • 36
0
votes
1 answer

What is the use of CompletionHandler in AsynchronousFileChannel for reading data?

I am working with the AsynchronousFileChannel for reading on the data. For reading the data, i found two read methods as follows: //1. Future java.nio.channels.AsynchronousFileChannel.read(ByteBuffer dst, long position); //2. void…
KayV
  • 12,987
  • 11
  • 98
  • 148
0
votes
0 answers

Can not closing a FileOutputStream cause Issue?

I have a scenario where I have created Lock objects with initialization of FileOutputStream using below code. This objects are supposed to be there in application throughout lifetime.I have a static Arraylist where i will be adding this lock…
csk
  • 566
  • 1
  • 5
  • 15