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

What is the format of writing and reading with RandomAcessFile

char[] input =new char[24]; for (int i=0; i<24; i++){ input[i] = (char)('a'+i); } RandomAccessFile bf = new RandomAccessFile("data1.txt", "rw"); for(int i=0; i<24; i++){ …
user3495562
  • 335
  • 1
  • 4
  • 16
0
votes
1 answer

how to read the string from file using RandomAccessFile?

my file content contains four columns 001 mike 1122 98 002 stephen 1232 97 Using RandomAccessFile i need to store the each column in its respective array types. readInt() is used to read Integer of column 1 how can i read the strings(column 2)…
0
votes
2 answers

Delete file contents using RandomAccessFile

I have a file which contains lot of zeros and as per the requirement the zeros in the file are invalid. I am using RandomAccessFile api to locate data in the file. Is there way so that all the zeros can be removed from the file using the same api.
Akg
  • 349
  • 1
  • 3
  • 15
0
votes
1 answer

Get filepointer position while reading data from an ObjectInputStream

I need to get the current filepointer-position (in bytes) when I read from my binary file. I wrote the file using ObjectOutputStream, and now I need to read it and remember the byte-position of each object. However: ObjectInputStream doesn't provide…
ElectRocnic
  • 1,275
  • 1
  • 14
  • 25
0
votes
1 answer

Writing data to a file using RandomAccessFile

I am writing to a file using RandomAccessFile.The data(fields) are stored in fixed field length,e.g every field would alloted space of 16 bytes.I write something by placing the pointer to the appropriate position using seek(). Problem comes when I…
Sameer Sarmah
  • 1,052
  • 4
  • 15
  • 33
0
votes
1 answer

Converting a file to an accessible object

Summary: I am trying to write a utility program that is based on the information contained in a separate file. The object has to be such that any information on the physical file can be retrieved quickly and can be updated quickly as…
Hungry Blue Dev
  • 1,313
  • 16
  • 30
0
votes
1 answer

How would I take information from a Random Access File and place it into several arrays?

I'm having a bit of trouble figuring this out. I'm supposed to read information from a Random Access File that was provided to me and then place the information into several arrays(firstName,lastName,age,gpa,computerClub). I was told what each type…
Iccirrus
  • 11
  • 1
  • 2
  • 4
0
votes
2 answers

How to open USB flash as RandomAccessFile in Java

Opening USB flash in Java as a RandomAccessFile has problems with seek, length and setLength methods. Small example of code: try { RandomAccessFile raf = new RandomAccessFile("\\\\.\\G:", "r"); raf.seek(10); …
Alex
  • 91
  • 1
  • 8
0
votes
1 answer

RandomAccessFile setLength(0) adding a string of null characters to a file

I am trying to clear the contents of a file I made in java. The file is created by a PrintWriter call. I read here that one can use RandomAccessFile to do so, and read somewhere else that this is in fact better to use than calling a new…
ErikAGriffin
  • 739
  • 3
  • 10
  • 21
0
votes
2 answers

Clear contents of a file in Java using RandomAccessFile

I am trying to clear the contents of a file I made in java. The file is created by a PrintWriter call. I read here that one can use RandomAccessFile to do so, and read somewhere else that this is in fact better to use than calling a new…
ErikAGriffin
  • 739
  • 3
  • 10
  • 21
0
votes
3 answers

file.writeDouble is not writing a double

I have a file: RandomAccessFile file = new RandomAccessFile("files/bank.txt", "r"); And I am reading and writing data to/from this file using: for (int pos = 0; pos < 1000; pos++) { file.seek(40 * pos + 30); double money =…
user2853108
  • 1,291
  • 3
  • 12
  • 15
0
votes
0 answers

replace double in a random access file

I am using the following to go through a dat file and I am hoping to replace money with another double value. try { RandomAccessFile file = new RandomAccessFile("files/bank.dat","r"); FileChannel poos; for(int pos = 0; pos < 1000;…
user2853108
  • 1,291
  • 3
  • 12
  • 15
0
votes
1 answer

random access data file in ASP.NET not permitted?

I am trying to use random access data file in ASP.NET. "rd4" is my application name. It works well in localhost, but it showed the following error message. Setting the read/write permission at the server does not help. Any suggestions will be…
user1617676
  • 361
  • 1
  • 3
  • 12
0
votes
1 answer

Same behavior of read line with java randomAccessFile on x32 or x64?

I use java 6 method readByte() from class randomAccessFile to read text files on linux x64. I'm looking the end of text line by finding "0xD" or "0xA" at the end. My question is : in case operating system will switch to x32 , will the find…
Toren
  • 6,648
  • 12
  • 41
  • 62
0
votes
1 answer

Replace a line with RandomAccessFile

I have a text file with this…
Ehsan
  • 2,273
  • 8
  • 36
  • 70