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

How can I open an existing directory using RandomAccessFile in Java?

I want to open a directory using RandomAccessFile. Can I do that?
erfdsg
  • 29
  • 7
-1
votes
1 answer

Read x number of bytes from a RandomAccessFile

Is there a way to read a certain number of bytes from a RandomAccessFile in Java?
Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
-1
votes
2 answers

Is it possible open a RandomAccessFile with the default associated program?

I have a file loaded in memory, through the RandomAccessFile (in java). Do not put it in the disc because it is a temporary file, and it is very important not to be stored for their safety. Is it possible RandomAccessFile open with the default…
user60108
  • 3,270
  • 2
  • 27
  • 43
-2
votes
1 answer

Write and Read file with RandomAccessFile in Java

Hello I am writing a program that write and read file XML in Java. Here is the Writing file public static void main(String[] args) throws IOException { File file = new File("C:\\Test\\employee.XML"); RandomAccessFile randomAccessFile = new…
Tuan Do
  • 9
  • 5
-2
votes
1 answer

Where is my data written to disk using RandomAccessFile in Linux?

I have encountered a problem that confused me for some time. In Linux, I logged in as a root user. Then I wrote a Java program that used RandomAccessFile to write data to disk first, then I deleted the file. But the program continued to run without…
ronhunlam
  • 3
  • 5
-2
votes
1 answer

Why does InputStream read method block the resource?

Why does InputStream's read method block the resource when there's nothing to read? Let's say I've a RandomAccessFile opened in RW mode, and I create InputStream / OutputStream using File Descriptor. Thread 1 is trying to read from the file, while…
user10543142
-2
votes
2 answers

Reading in shorts in a RandomAccessFile .csv

I'm trying to read in a .csv file with 3 shorts in the beginning of the file. I need to read them in and I'm setting to a variable but it seems to not be pulling in the right data. private short M = 0; private short rootPtr = 0; private short N =…
-2
votes
1 answer

How does Random Access File Work

I 'm starting to learn Java I / O and i started with Random Access File,I cant find any good information about using Random Access File if some one cant give me some good references to how it works Does it read/write binary or text files? how can i…
Ricki
  • 141
  • 3
  • 16
-2
votes
1 answer

Switch statement issue

I've made some modifications and now I'm having an issue with my switch statement. The functions are supposed to read random access files. When I run the program, it displays the menu and when I choose an option it only outputs the first option I…
-2
votes
1 answer

Writing to a file with RandomAccessFile#write()

lets say i have a program that makes a binary file called data.bin and i write a bunch of random information to it using data.write(item) like: RandomAccessFile data = new RandomAccessFile("data.bin","rws"); Random r = new Random(482010); …
MadeInJapan
  • 45
  • 1
  • 8
-2
votes
2 answers

how can I save data into text file by using random access file and then 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…
-3
votes
1 answer

(JAVA) Read "buffer" bytes (or "y" bytes if (y < buffer)) from a file

I'm trying to read bytes from a file "A". I'm using a RandomAccessFile to seek a position and then I need to read "y" bytes. I have a buffer of 4096 bytes and if the "y" is not multiple of 4096, I read more bytes than I should. If I set the buffer…
Rafael Tavares
  • 5,678
  • 4
  • 32
  • 48
-4
votes
4 answers

How to display random ques from text file in vb?

I have created a Quiz application in Visual Basic.I have stored the questions in a text file and I'm using streamreader to read the lines.The text file looks like this If x is the first of five consecutive odd numbers then what is their average…
user6024733
-4
votes
3 answers

Java-Write in file

I want get name, last name and a spacial code from user, and save in one array, after that write to a file. My code doesn't have compiler error but it doesn't work. public class WriteFile { public static void main(String[] args){ try { …
Farzaneh
  • 3
  • 2
1 2 3
23
24