Questions tagged [randomaccessfile]

Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

A new FileDescriptor object is created to represent the connection to the file. The mode argument specifies the access mode with which the file is to be opened. The permitted values and their meanings are as specified for the RandomAccessFile(File,String) constructor.

If there is a security manager, its checkRead method is called with the name argument as its argument to see if read access to the file is allowed. If the mode allows writing, the security manager's checkWrite method is also called with the name argument as its argument to see if write access to the file is allowed.

Parameters

  • name - the system-dependent filename
  • mode - the access mode

Throws

  • IllegalArgumentException - if the mode argument is not equal to one of "r", "rw", "rws", or "rwd"
  • FileNotFoundException - if the mode is "r" but the given string does not denote an existing regular file, or if the mode begins with "rw" but the given string does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
  • SecurityException - if a security manager exists and its checkRead method denies read access to the file or the mode is "rw" and the security manager's checkWrite method denies write access to the file
359 questions
1
vote
2 answers

Fast random access read/write access on big files in java

I'm creating endgame database files for a game. Multiple threads compute the results of game positions, saving the result at the appropriate place in the file, but also consulting the sofar database in order to speedup the computation. Until now…
Tobs40
  • 65
  • 7
1
vote
3 answers

The readChar() method displays japanese character

I'm trying to write a code that pick-up a word from a file according to an index entered by the user but the problem is that the method readChar() from the RandomAccessFile class is returning japanese characters, I must admit that it's not the first…
ben624
  • 177
  • 1
  • 3
  • 11
1
vote
1 answer

Create a file of a given size and type in java

I'm using this code to generate a file of a given size in java: File file = new File(basedir, filePath); file.getParentFile().mkdirs(); RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.setLength(sizeInBytes); raf.close(); I'm creating a…
Kreender
  • 284
  • 1
  • 6
  • 17
1
vote
1 answer

Merge multiple files using java

I have a file in parts. I have to merge them all to in file. I am merging them using RandomAccessFile and it's working fine but for larger files it is very slow. Here is the code I am using for merging them: RandomAccessFile outFile = new…
1
vote
0 answers

"flush between consecutive read and write" error still remains with fflush

I am reading and writing a struct to/from a random access file. File pointer is defined in the main function and passed to other functions. I tried to put fflush everywhere that I can yet I still get this error. I don't know what I am…
aulven
  • 521
  • 3
  • 14
1
vote
0 answers

java RandomAccessFile EOFException

I am trying to check whether a certain position in RandomAcceessFile is empty in order to avoid overwriting some data before writing in the file. I initialized a very large RandomAccessFile: randAccFile = new RandomAccessFile( DIR + "/" + FILENAME,…
vcucu
  • 184
  • 3
  • 12
1
vote
1 answer

Random Access File seems to switch from UTF-16 BE to UTF-16 LE after I run code to "delete" data from file

I have this project for a java class where I have to make a random access file that can contain data and do things with the data. However, I've ran into a problem where "deleting" a piece of data (replacing all the lines related to it to "SPACE")…
1
vote
1 answer

Can you access files on the remote FTP server with RandomAccessFile?

I'm trying to read the file on the FTP remote-server using Apache Commons Net library. retrieveFileStream returns InputStream and put it in BufferedReader. But, I want to use RandomAccessFile (to use the seek() method). I want to get Inputstream as…
1
vote
0 answers

Displaying Results

I am able to input data into the program and used some printf statements to see if the data is being written properly. When I got to either print one record or all records, the program either forces and exit (dispAll) or gets gibberish and displays…
1
vote
1 answer

Analog of raf.seek(pos)

I wanna find analog of raf.seek(pos) method from java. Need to find page by number in text file (book's page). val raf = RandomAccessFile(file, "r") raf.seek(pageNumber * PAGE_SIZE) raf.read(bytePage) I don't like my version. It's too java…
Dister
  • 13
  • 5
1
vote
2 answers

writeInt(Integer) overwrites zero

Using RandomAccessFile class, I'm trying to test the concept of writing/reading to/from a file in java. So I tried this code: public static void main (String[] args) throws IOException { RandomAccessFile storage = new…
1
vote
1 answer

Choose random file in Maxscript

How to choose any random file from a folder using MaxScript? files = getFiles "c:\\base\\*.max" for f in files do random (mergeMAXFile f)
Daymon
  • 11
  • 1
1
vote
1 answer

Open old VB6 Random Access File using C#

I'm trying to open old VB6 files which were created using random access. The Type used was as follows: Type CDB dateCreated As Date lastModified As Date companyName As String * 30 ownerName As String * 30 contactName As String *…
1
vote
1 answer

How can I mimic a random access file in Python

So the course that I am teaching has a requirement to teach the concept of random files - the course content specifies that the files are of a fixed size/length, each location contains a record, and the location in which to store/from which to read…
Robert Flook
  • 307
  • 6
  • 12
1
vote
1 answer

Code runs when in a main method but not when in another method

I created the setArtwork method to set the artwork of an aac file in an .m4a container and it does exactly what I want it to when I run the main method public static void setArtwork(File art, File m4a) throws Exception{ Mp4TagReader reader = new…