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
0 answers

Show graphic progress while copying files using File Channels

I am new to Swing Applications. I have a simple app that copies files from a directory to another one. To copy the files I use FileChannel instances. I was wondering if it is possible to show a progress bar to inform the user How much of the files…
John Kananakis
  • 133
  • 1
  • 9
0
votes
3 answers

Get position at file channel

I have a class that copies one file from one folder to another : public class Foo extends JFrame{ Timer t; FileChannel inp = null, outp= null; File sourceFile = new File("C:/movies/movie.mkv"), destFile = new…
user5721321
0
votes
1 answer

Byte Allocation Affecting the file transfer in JAVA NIO

I have a 7Gig file to send using JAVA NIO in 2 scenarios: First is the client will be the one sending the file and I allocate the buffer to be 500MB it is fast it took only 30sec Second is the server will be one sending the file and I still used…
0
votes
3 answers

Handling large images

I am building an app on which I to deal with extra large images like of 10000X5000 pixels.The app crashes when I tried to display such images on ImageView. I can't go for bitmap sampling as I can't change the size of images. A simple work is to…
Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70
0
votes
0 answers

How to check file is opened or not in java is not working

I try to check file is opened or not in java using following examples . I use Apache Commons IO library... boolean isFileUnlocked = false; try { org.apache.commons.io.FileUtils.touch(yourFile); isFileUnlocked = true; } catch (IOException e)…
Terance Wijesuriya
  • 1,928
  • 9
  • 31
  • 61
0
votes
1 answer

FileChannel - append byte buffer at eof?

I wondered if there is a possibility to add a byte buffer to the end of a file by using the file channel's position method. I have read that it is neccessary to open the file output stream with the append flag ByteBuffer byteBuffer =…
jam
  • 1,253
  • 1
  • 12
  • 26
0
votes
1 answer

Incomplete File Copy Java NIO

I'm having problem with reading my file. Im quite new to NIO too. The actual size of the file I want to send to the server is almost 900MB and only received 3MB. The server's side code for reading: private void read(SelectionKey key) throws…
jnapor
  • 63
  • 1
  • 1
  • 9
0
votes
2 answers

Writing to multiple Filechannels repetitively

Here is some code i made to write succesively and repetitively to multiple filechannels. The files get made, there are no errors, but nothing gets written. The important part is where the buffer is written : "listofChan[j].write(buff);" . Why is…
0
votes
1 answer

What's the alternative for BufferedWriter in Java NIO

If we are using Java Standard IO api's to read a file line by line and manipulate line and write it to a new file. We would be using a snippet something like this. BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos,…
saiki4116
  • 323
  • 1
  • 4
  • 14
0
votes
2 answers

Why my output file's size is less than origin file?

I want to transfer big file by file channel efficiently, so I use java.io.RandomAccessFile and java.nio.channels.FileChannel to transfer file. And I get the output file is not right, which is less than the origin source file. Here is the code: …
Yanhui Zhou
  • 872
  • 6
  • 20
0
votes
1 answer

Java Rolling File Creation Fails when attempting to read simultaneously

I am using java.util logging classes to create a rolling file appender. I want to create a log reader that reads from these logs as data is written to them. The rolling log appender code works fine on its own. But once I start the reader thread new…
Guru
  • 3
  • 1
0
votes
0 answers

Read and write to a particular line in large textfile java

I'm using Stream to read a particular line from file and with the help of pre-calculated Byte position value I'm using FileChannel and ByteBuffer to write to same location in a big file. Basically editing some values in textFile. //Read a particular…
user1799214
  • 511
  • 2
  • 11
  • 25
0
votes
0 answers

Additional character while rewriting to file using FileChannel and RandonAccessFile

I'm trying to replace existing text from a large text file using randonAccessFile and FileChannel. This is what I have right now public void updateText(final long position, final String newData) throws IOException { RandomAccessFile file =…
user1799214
  • 511
  • 2
  • 11
  • 25
0
votes
1 answer

Why Java Gathering Write with Offset doesn't exist?

Java's FileChannel supports writing from an array of buffers to a channel in a gathering write with int write(ByteBuffer[] src). It does not however support an equivalent of the write with offset method write(ByteBuffer src, long position). There…
tvoss
  • 11
  • 1
0
votes
0 answers

Loosing data with (GatheringByteChannel) RandomAccessFile.getChannel.write(buffers)

I open raf, get file channel, accumulate some data in buffers then channel.position(raf.length) channel.write(buffers) channel.close raf.close I expect that bytes are written into raf at these offsets, which are raf.length + accumulated buffer…