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
0
votes
1 answer

JAVA - Retrieve NMEA frame from a GPS Receptor -More details about RandomAccessFile WriteBytes method

I have a GPS receptor. I retrieve all the NMEA frames captured by this one in the Eclipse console. EDIT - This is my full class : public class GPSFrame extends Observable implements Runnable { static Thread myThread=null; static…
Tofuw
  • 908
  • 5
  • 16
  • 35
0
votes
1 answer

FileNotFound exception with RandomAccessFile using Path obtained from WatchService?

Why would obtaining a RandomAccessFile(path.toFile(),"rw") produce a FileNotFoundException from a Path that was returned from WatchService and the WatchEvent kind is ENTRY_CREATE? java.io.FileNotFoundException:…
The Coordinator
  • 13,007
  • 11
  • 44
  • 73
0
votes
1 answer

Random Access files: Reading and Writing

What I basically want to do is that I first write a char "123" to the file test2.txt. Then I read it, store the read value in the variable z(char datatype) and compare it with "123" in the (if) part. But it returns NO MATCH... Even though the value…
0
votes
1 answer

Java transferFrom Part of binary file?

Im tring to transfer from a file filein starting at position 1300 (in uint8 pieces) into fileto, using the RandomAccessFile transferFrom function. fromfile = java.io.RandomAccessFile(ifile, 'rw'); fromchannel = fromfile.getChannel(); tofile =…
Alex Byasse
  • 322
  • 2
  • 5
  • 16
0
votes
1 answer

Java RandomAccessFile setLength but for the start of binary file

I've been reading on RandomAccessFile and understand that its possible to truncate the end of a file by setLength to a length shorter than the file. Im trying to copy just the "end" of the file to a new file and truncate the beginning. So for…
Alex Byasse
  • 322
  • 2
  • 5
  • 16
0
votes
1 answer

Java - Writing a file using randomAccessFile

I am trying a create a .dat file that is split into 5 columns each with the heading, "timestamp", "deviceId", "testId", "Availability" and "Latency". This file is going to be pointed to a database where there are tests being ran at the moment. The…
Dan
  • 2,020
  • 5
  • 32
  • 55
0
votes
1 answer

RandomAccessFile reading Cyrillic UTF-8 java

mates! I have trouble reading from file Cyrillic text using RandomAccessFile. Here's a simple program, that writes information in specific file (Cyrillic words) using such format: keyLength, valueLength, key, value Then program tries to read this…
NinjaTurtle
  • 41
  • 2
  • 10
0
votes
1 answer

RandomAccessFile: Adding space after last item?

I am writing a program that allows the user to write to a text file using randomaccessfile. The user enters name, age, and address, and each of these items is 20 bytes, so the record length is 60 bytes. When the user wants to search for a record,…
TheEyesHaveIt
  • 980
  • 5
  • 16
  • 33
0
votes
1 answer

RandomAccessFile: Getting Java.io.EOFException

I have the code: junk.writeUTF("Jim"); junk.writeInt(9304029); junk.writeUTF("England"); junk.writeUTF("Bob"); junk.writeInt(99291933); junk.writeUTF("Canada"); junk.seek(12); String name = junk.readUTF(); int number = junk.readInt(); String city…
TheEyesHaveIt
  • 980
  • 5
  • 16
  • 33
0
votes
1 answer

RandomAccessFile: Setting all items to the same number of bytes?

junk.writeBytes("Henry McCollum"); junk.writeInt = 9304029494; junk.writeBytes("Toronto"); If the above example were all ints, I could just set the record size to be equal to 12(since 3 ints * 4 bytes = 12), but how would I know how big the 2…
TheEyesHaveIt
  • 980
  • 5
  • 16
  • 33
0
votes
3 answers

Problems reading from binary file or creating it

When I create the file I use the dataoutputstream to write one 'int' at a time: Database.write(0) Of course it doesn't say 0 it's a variable there but I printed it and the first one is 0 so I'm taking that one as an example. Now I'm not 100% sure,…
David Ekermann
  • 87
  • 3
  • 13
0
votes
1 answer

Where should the close() function be called for this RandomAccessFile object

I have a class called GraphView that extends View and I do some calculations in side this class The object of this class represents a custom Graph that I display on the screen. This is created in the MainActivity file I need to save the value of…
user13267
  • 6,871
  • 28
  • 80
  • 138
0
votes
1 answer

Checking null position using RandomAccessFile

I need to check if a position in a random access file has not been written to. The problem with this is, when the position actually hasn't been written to, I get (as anticipated) an EOFException. I have been reading RandomAccessFile documentation to…
Dillon Burton
  • 363
  • 6
  • 16
0
votes
1 answer

java RandomAccessFile parameter

I am trying to follow the below example found it here Java: Find if the last line of a file is empty to determine if a file finish by CRLF(empty line) however when I pass a String to the method RandomAccessFile says file Not Found. the problem is I…
0
votes
0 answers

Read a large bin file

I want to read a large bin file which contains M successions of double numbers, which repeat in a predefined order as: A0, A1, A2... AN, B0, B1, B2... BN... (M times) I am not allowed to read the file at once because the file can be too large, that…
arjacsoh
  • 8,932
  • 28
  • 106
  • 166