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

Can I reverse the filechannel with certain bytes overpassed

In my programming, I do not know how many bytes I need to read for a certain object util I processed it. But I know at most it is 1024 bytes. After processing the object, how can I put the remaining bytes back to the file i.e., revserse the fc by…
user3495562
  • 335
  • 1
  • 4
  • 16
0
votes
1 answer

how to rewind filechannel

in my homework we need to use fc.position(position) to locate the contents, but after that I need to rewind fc in order to recursive do this, what should I do, it seems there is no rewind method for fc
user3495562
  • 335
  • 1
  • 4
  • 16
0
votes
2 answers

End of file using ByteBuffer and FileChannel

I write a small code, say ByteBuffer buffer = ByteBuffer.allocate(10); int w= fc.read(buffer); System.out.println(w); w= fc.read(buffer); System.out.println(w); w= fc.read(buffer); System.out.println(w); say the file contains 10 bytes, the result…
user3495562
  • 335
  • 1
  • 4
  • 16
0
votes
1 answer

MappedByteBuffer slow on initial run

long time reader, first time poster. I'm having a bit of trouble reading data quickly from a set of binary files. ByteBuffers and MappedBytBuffers offer the performance I require but they seem to require an initial run to warm up. I'm not sure if…
0
votes
1 answer

fileoutputstream in Java generating zero byte if source destination are same?

We are using filecopy in Java using similar code: private void copyFileUsingFileChannels(File source, File dest) throws IOException { FileChannel inputChannel = null; FileChannel outputChannel = null; try { inputChannel = new…
garuda
  • 67
  • 1
  • 2
  • 8
0
votes
0 answers

Image and videos unreadable after move in Android

I'm using this functions to move some images and videos to custom folders: public static void moveFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new…
iGio90
  • 3,251
  • 7
  • 30
  • 43
0
votes
1 answer

Java NIO2: Need clarification on FileChannel

I'm trying to build a custom FileChannel, and I'm experiencing a lack of clarity due to inconsistency in the documentation. The documentation for the FileChannel.transferFrom(ReadableByteChannel src, long position, long count) method says, If the…
Harry
  • 3,684
  • 6
  • 39
  • 48
0
votes
1 answer

Inquiry about opening a FIleChannel

Why opening a FileChannel in the following way: FileChannel.open(path,StandardOpenOption.READ,StandardOpenOption.APPEND); gives an exception? I know that it's specified by the API. However I would like to know why it's allowed with the combination…
Rollerball
  • 12,618
  • 23
  • 92
  • 161
0
votes
1 answer

Flume NG FileChannel is very slow

I have been experimenting with flume ng (flume-ng-1.2.0+24.81-1~lucid) and have been comparing the performance of the memory channel and file channel. Each event in my test system is 1KB in size and with my current configuration I am able to handle…
Telax
  • 103
  • 1
  • 3
  • 8
0
votes
2 answers

Writing data to file is erasing everything before it(Placing 00's) and changing the file size

I have a program which writes out some data- I am using this logic FileOutputStream outpre = new FileOutputStream(getfile()); FileChannel ch = outpre.getChannel(); ch.position(startwr); ch.write(ByteBuffer.wrap(dsave)); outpre.close(); It writes…
0
votes
1 answer

Read and Write with File channel

I need help on the file operation using FileChannel . My requirement is, I have to read a big file from the system, then need to check the file line by line. If certain strings found then need to add new lines or delete old lines from the file. And…
Souvik
  • 1,219
  • 3
  • 16
  • 38
0
votes
3 answers

Java Reading from a File using FileChannel

I've been getting some strange outputs from this code upon reading from a large file, the file was printed using a while loop to 99,999 digits however, upon reading the file and printing the contents it only outputs 99,988 lines. Also, is using a…
Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60
0
votes
1 answer

IOUtils.closeQuitely for FileChannel

I wanted to know the Apache library method IOUtils.closeQuitely does well with FileChannel. I see it takes Closeable as argument and FileChannel does implement it up in hierarachy. But can we face any issue down the line. Any experience one can…
Ahmad Beg
  • 4,285
  • 3
  • 14
  • 5
0
votes
0 answers

Can transferto/from be used with a file channel that is assigned to a named pipe

I have a setup where one program reads from a named pipe and writes the read data to a socket. Another program reads from the socket and writes the data to another named pipe. This is on Linux across nodes. It all works fine doing regular reads…
user1922871
  • 103
  • 6
0
votes
1 answer

How to write and read a string property in a Java Object from a file with FileChannel and ByteBuffer

Following is a sample class showing how I put String into ByteBuffer. I am able to write String to a file like this, but I am not sure how can I know the size of byte array to read the title back again when deserializing. public class TestClass { …
Amit Gill
  • 35
  • 1
  • 7
1 2 3
12
13