FileChannel « API « Java I/O Q&A





1. Why can't I obtain a FileChannel from a FileWriter?    stackoverflow.com

I'm wandering why getChannel is only implemented in FileOutputStream and not in FileWriter. Is there any true reason ? Is there a way to lock a FileWriter another way ? thanks... ...

2. java FileChannel transferFrom questions?    stackoverflow.com

Following is my method to append one file onto another file.

public static void appendFile(File baseFile, File newFile) throws IOException {
    long baseFileSize = baseFile.length();
    ...

3. Does Java FileChannel.tryLock work on Mac OS X?    stackoverflow.com

I have the code that similar to below. This code works fine on Windows and Linux but on Mac 10.5 and 10.6 gives java.io.Exception opertaion not supported. Many thanks for any ...

4. FileChannel.size() guaranteed to return correct size (including pending updates) in Sun JVM?    stackoverflow.com

In the Sun JVM, is the FileChannel.size() method guaranteed to return the correct size of the file, including any pending updates? In other words, is the following test guaranteed to pass ...

5. FileInput/OutputStream versus FileChannels -- anything decisive to say?    stackoverflow.com

I am writing a program that has to copy a sizeable, but not huge amount of data from folder to folder (in the range of several dozen photos at once). ...

6. Processing huge pipe delimited files    stackoverflow.com

With reference to my previous post Remove first line from a delimited file I was able to process smaller files and remove the first line .... but incase of huge files there ...

7. Should I close the FileChannel?    stackoverflow.com

I came across an issue with one of our utility classes today. It is a helper for files and contains some static file copy routines. Below are the relevant methods extracted ...

8. Java: obtain the filename from a opened RandomAccessFile instance    stackoverflow.com

How can I obtain the filename from a opened RandomAccessFile instance? I can find only the following methods related to the file itself:

  • getFD() : which returns a FileDescriptor object
  • getChannel() : which returns ...

9. FileReader VS. FileChannel    coderanch.com

Hi all, I am not sure if this is best hear or in performance but here goes: I have a function that I am updating to use NIO void build(File f) throws IOException { Reader r = new BufferedReader(new FileReader(f)); StreamTokenizer st = new StreamTokenizer(r); ... do stuff ... } void build(File f) throws IOException { FileChannel fc = (new FileInputStream(f)).getChannel(); ...





11. FileChannel and read method    coderanch.com

Hello, this is my first post on this forum and I have a question regarding NIO. I am trying to read data from a file using a FileChannel from a RandomAccessFile. It does work, but I am wondering whether the code that I am using is correct or not. Can anyone please tell me whether this: ByteBuffer bb = null; RandomAccessFile ...

12. Need help with FileChannel    coderanch.com

I need to download some .xls files from a web site. Since they are kind of big, about 17MB each, I rather not use BufferedReader to open them, read in the data and then write data to a local file. I noticed that FileChannel class has some really nice features, which makes transfer big files much faster and easier. But I ...

13. FileChannel problem    coderanch.com

I got a problem with a FileChannel object not writing all of the bytes I pass to it via a ByteBuffer array. fileChannel.write(byteBufferArray); Say, byteBufferArray has length 100 and each ByteBuffer object in it is one line of the file so the file should have 100 lines but it has less (only 16) fileChannel.write(byteBufferArray) only writes 16 array elements instead of ...

14. Filechannel    coderanch.com

Maybe your boss likes doing micro-management? Why would he even care? As an aside, I'd recommend using a proper FTP client like Jakarta Commons Net instead of rolling your own in that way. If for no other reason that sooner or later you'll need to switch directories or do some other FTP-specific task.

15. Reading bytes from FileChannel...    coderanch.com

Hi, I want to read file content into bytebuffer and then decode ByteBuffer bb to CharBuffer. At last i want to close the FileChannel and delete the inputFile. I tried the following program. FileChannel fc = new RandomAccessFile(inputFile, "r").getChannel(); ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); CharBuffer cb = Charset.forName("ISO-8859-1").decode(bb); The above program works fine. FileChannel.map() method directly maps to the file ...

16. Using FileChannel instead of RandomAccessFile    coderanch.com

Using FileChannel instead of RandomAccessFile (I/O and Streams forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java I/O and Streams Using FileChannel instead of RandomAccessFile Post by: Akhil Jain, Ranch Hand on Oct 24, 2007 00:03:00 Hi Guys, Can someone help me with this code. I have writen a simple ObjectStore using Random ...





17. BufferedReader and FileChannel    coderanch.com

I have this code (BufferedReader) to write data that I read from a table to an output file. ResultSet rs = stmt.executeQuery(); File outputDir = new File(sysObj.getOutputFileDirectory()); if (!outputDir.exists()) { outputDir.mkdir(); } String file = "out.csv"; String fileDetails = sysObj.getOutputFileDirectory().concat(file); BufferedWriter bw = new BufferedWriter(new FileWriter(fileDetails)); while (rs.next()) { for (int i = 1; i <= neededList.size(); i++) { Object o ...

18. RandomAccessFile, FileChannel, MappedByteBuffer...    coderanch.com

Hello! We have the following problem, which drives us insane. We want to insert some text (with a given length) into a file at a given position, but we want that the content at this position will NOT be overwritten. Instead, we want to slide this content for the given length of the new insert "to the right". We have a ...

19. FileChannel rollback question    coderanch.com

20. FileChannel class    coderanch.com

I am trying to finish up a homework assignment and I am having a little bit of trouble. I am using the FileChannel class to copy input from one file to another. My program will compile but I am not for sure what else to do? I think my problem is in creating a file to be copied. I have created ...

21. About FileChannel    coderanch.com

22. Reading file using FileChannel    coderanch.com

File FILE = new File("C:\\primes.txt"); FileChannel fileChannel = new FileInputStream(FILE).getChannel(); //MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); ByteBuffer buffer = ByteBuffer.allocate((int)fileChannel.size()); fileChannel.read(buffer); CharBuffer cb = decoder.decode(buffer); BufferedReader br = new BufferedReader(new CharArrayReader(cb.array())); String line; while ((line = br.readLine()) != null) { System.out.println(" FileChannel : "+line); } in 11th line code , its not printing the line string value which is reading from ...

23. File getting deleted on Mac System even though locked using FileChannel.lock()    coderanch.com

Hi folks, I have written a utility method to delete the file if its not currently being used by other threads (using simple IO). To test it I have written the test case. In which I will spawn a thread which will use FileChannel's lock or tryLock to obtain a lock and this thread goes to sleep. Other thread will try ...

24. FileChannel    java-forums.org

25. Does FileChannel's transferFrom lock?    forums.oracle.com

26. FileChannel question    forums.oracle.com

say I have the following: FileInputStream fis = new FileInputStream("somefile"); DataInputStream dis = new DataInputStream(fis); FileChannel fc = fis.getChannel(); I know that if I do a read on fis, the position of the FileChannel (fc) will advance the amount I read from fis, my question is what if I do a read using dis, will this advance the position of the ...

27. FileChannel Help    forums.oracle.com

import java.io.*; import java.nio.channels.FileChannel; public class FileCopy { private static void copyDir(String sDir, String tDir) throws IOException { File targetDir=new File(tDir); if(!targetDir.exists()) { System.out.println("Creating"+targetDir.getPath()); targetDir.mkdirs(); } } private static void copyFile(File toBeCopied, File newCopy) throws IOException { FileInputStream fis=new FileInputStream(toBeCopied); FileChannel fcin=fis.getChannel(); FileOutputStream fos=new FileOutputStream(newCopy); FileChannel fcout=fos.getChannel(); fcin.transferTo(0,fcin.size(),fcout); fcin.close(); fcout.close(); fis.close(); fos.close(); } public static void main(String[] args) throws IOException { ...

28. Can i use FileChannel in a non-blocking way?    forums.oracle.com

29. using xerces DOM instead of FileChannel    forums.oracle.com

I was just wondering if using xerces DOM will give better performance. We have set -Xmx as 8GB on HP unix. and need to process XML files each of which can be from 1KB to 20-30 MB.(like seraching for nodes and prcocessing) and we have 3-4 JVMs running each with say 100 threads. and each thread will be processing the XML ...