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

How the RandomAccessFile class returns bytes with randomAccessFile.read() method;

I'm using the google translator , I hope the question is well understood. There is one thing I do not understand the random access files .No understand how the program works but it works. This is my program : //…
Marquake
  • 191
  • 1
  • 3
  • 10
2
votes
1 answer

VB.net - Overwriting random access file

This part of my program is designed to add user details to a random access file. The sub routine below is designed to do this: 'This allows a user to be added to the User File Dim UserToAdd As User Dim UserFile As Integer Dim…
stizzo96
  • 666
  • 1
  • 7
  • 15
2
votes
1 answer

How do I insert random images from my drawable folder to randomly appear on the screen when loaded?

I have 15 Images in my drawable folder and want 6 of these random images from this folder to be inserted into given locations when I open this page. Any help will be greatly appreciated. Below is my xml
2
votes
0 answers

Android: Creating file in memory (Not in Filesystem) Using RandomAccessFile and MappedByteBuffer

I am having a data in bytes, and i want to write it into a memory location (not in a file at a location). To do this i am using RandomAccessFile and MappedByteBuffer based on this link The code looks good and worked fine only when i give a absolute…
Sudarshan
  • 1,291
  • 3
  • 26
  • 35
2
votes
3 answers

Java BigInteger with very large binary numbers

i have 2 very large binary numbers (144 digits). I want to write them in different RandomAccessFiles and then read the files to memory and check to see which number is bigger. What i did so far: 1. I created a BigInteger: BigInteger big = new…
George
  • 21
  • 2
2
votes
1 answer

JAVA RandomAccessFile throws IOException when constructed

I am trying to access a file to read it and write on it using this code: RandomAccessFile file1 = new RandomAccessFile("C:\\lol.txt", "rw"); It returns me an error "File not Found (IOException)". The file exists and it is in that exact folder. What…
John Black
  • 305
  • 2
  • 8
  • 19
2
votes
0 answers

RandomAccessFile not closing

I'm trying to rename a file which I have access by RandomAccessFile. When I do all changes I want in the temporary archive, I close the two RAF. But when I try to move the file, to rename(replacing) it says that my archives are been used by other…
Francisco Cabral
  • 856
  • 11
  • 21
2
votes
5 answers

new line in Random Access File in java

Whenever using the 'writeBytes' method of RandomAccessFile in java,it writes the text in the same line in the file. How can I get to a new line with RandomAccessFile only? (No BufferedReader).
aceBox
  • 711
  • 2
  • 13
  • 30
2
votes
2 answers

How Can save data in text file using random access file and update these data?

I'm confused how can I save my data for example I hava (Student ID , Name , Surname) the only Student ID is Integer, I want save these data to text file when I Press (AddButtton) and then I want to update these data when I press (UpdateButton),the…
salih
  • 21
  • 3
2
votes
2 answers

Search for a string in large file and save it's position in Java

I'm searching for a way to parse large files (about 5-10Go) and search for position (in byte) of some recurrent strings, the fastest as possible. I've tried to use the RandomAccessFile reader by doing something like bellow: RandomAccessFile…
pierrefevrier
  • 1,570
  • 4
  • 22
  • 33
2
votes
2 answers

Read external log file without creating file-lock

Trying to read a log file line-by-line (in Java). This log file is being written to simultaneously by another process (non-java program). I have 2 approaches - BufferedReader (BufferedReader br = new BufferedReader(new…
Quest Monger
  • 8,252
  • 11
  • 37
  • 43
2
votes
1 answer

Creating Large Files in Java (2gb+)

I'm currently working on a project to create a large random binary file (2gb to 10gb) and I'm at a loss for ideas. Obviously writing out 10gb worth of data would take forever and I need a timely approach. My latest idea was to create a random…
Dommol
  • 191
  • 1
  • 17
1
vote
0 answers

Java RandomAccessFile equivalent in JavaScript or Nodejs

I have the following java class that generates WAV audio file from PCM data. I want to implement the same functionality in JavaScript or NodeJS equivalent. Is there any existing library you can recommend? There's an existing NPM library out there…
1
vote
0 answers

RandomAccessFile class - trouble with readiing/writing first item of LinkedHashMap

Here is the main code: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile("test.dat", "rwd"); Map
MrJ_
  • 55
  • 7
1
vote
1 answer

seek() method not working with InputStream available() method in java

I am working on this java problem, where I have to write to a text file on the system without tempering existing text data on that file, I am using randomAceessFile.seek((inputStream.available()+1)); to point my pointer 1 space ahead of existing…