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

Confused about: RandomAccessFile.readFully(byte[] b)

lets say byte[] b = 1024 for(int k = 0; k < 10; k++) data.readFully(b); does the readFully() method increment by itself if it is put inside of a loop kind of like the nextLine() method? or will continue to read the same 1024 bytes over and…
MadeInJapan
  • 45
  • 1
  • 8
0
votes
1 answer

readUTF works once, then throws EOFException

I'm writing to a RandomAccessFile like that: (in a LinkedList's subclass) file.setLength(0); for (Person person : this) file.writeUTF(person.getBlob()); Person.getBlob() returns a string of constant length, containing only basic alphanumeric…
gronostaj
  • 2,231
  • 2
  • 23
  • 43
0
votes
2 answers

How do I write and delete Objects from a RandomAccessFile?

I am currently working on a school project for which I need to save my data to a RandomAccessFile. I figured that this is by far not the most efficient way, but I have to do it. Note: I have to use the RandomAccessFile class. I understand how I can…
Nino
  • 17
  • 1
  • 9
0
votes
0 answers

Java : how to write string to .txt as byte using RandomAccessFile

First of all I read many about this question. However none of them was my solution. I am trying to read string from console and write it to the .txt as byte. I tried FileWriter/BurfferWriter. But ,for example, I am typing "abcd" from console, then I…
Burak Keceli
  • 933
  • 1
  • 15
  • 31
0
votes
2 answers

reading data from a randomaccessfile

Here is the function I have : // Read a record from the specified RandomAccessFile public void read( RandomAccessFile file ) throws IOException { account = file.readInt(); byte b1[] = new byte[ 15 ]; file.readFully( b1 ); …
Ahoura Ghotbi
  • 2,866
  • 12
  • 36
  • 65
0
votes
1 answer

Writing data into RandomAccessFile

In my project i need to create a file for each student and i thinki have the method created, here it is below public addStudent(String fullName, int grn, String formClass, String formTeacher) { //Default values int creativity…
0
votes
3 answers

How to allow multiple threads to access a random access file at the same time in Java

Is there a way I can allow multiple threads to perform read/write operations on a RandomAccessFile at the same time, i.e, concurrently? Do I have to use any synchronization object, or can it be done without using any synchronization?
JavaNewbie_M107
  • 2,007
  • 3
  • 21
  • 36
0
votes
1 answer

Having trouble releasing a Java FileLock

I haven't worked with nio much and I'm having some trouble with releasing a FileLock. Basically, in JVM-A I have a NON-SHARABLE write lock on a file which looks something like this: File lockfile = new File("m.lock"); RandomAccessFile writeFile =…
Michael Remijan
  • 687
  • 7
  • 22
0
votes
1 answer

Why does changing the way you initialise RandomAccessFile objects change FileChannel performance?

Im investigating the possibility of re-writing some code that bottlenecks on disk writes into java. The javadoc does not make clear why the first two code loops below would perform so differently to the second two loops: public void…
Jay
  • 19,649
  • 38
  • 121
  • 184
-1
votes
1 answer

Problem with input from user saved to file by RandomAccessFile methods

I've got a problem with input from user. I need to save input from user into binary file and when I read it and show it on the screen it isn't working properly. I dont want to put few hundreds of lines, so I will try to dexcribe it in more compact…
Daniel1490
  • 79
  • 6
-1
votes
3 answers

How to read byte correctly from file using Java RandomAccessFile?

I have a binary file with the byte 88 (which is 136 decimal). I'm using Java's RandomAccessFile class and the "read" method to read this byte via a pre-defined buffer. I also tried "readUnsignedByte()" but get the same issue as…
Morkus
  • 517
  • 7
  • 21
-1
votes
2 answers

Issue with "import java.io.RandomAccessFile;"

This is my homework assignment... "You are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand, and the cost of each one. Write a program that creates a…
hts95
  • 103
  • 1
  • 1
  • 9
-1
votes
1 answer

RandomAccessFile reading ISO-8859-1

I have a RandomAccessFile reading from a file that contains ISO-8859-1 characters (åäö). But when use seek() and readLine() on the file I get aagÃ¥rd instead of aagård. Any clue why this is?
tomoswizzard
  • 65
  • 1
  • 2
  • 6
-1
votes
1 answer

RandomAccessFile converting int to Chinese

I am trying to read some book objects that I have stored in a txt file. When I run the code it runs but returns incorrect information. Expected result: Book isbn=225346873945, price=12.99, yearPublished=2015, title='Finders Fee' Actual…
-1
votes
1 answer

get jpeg image tags from file structure

Hello my programmer friends :) Do you know file structure of jpeg image file? how can I get image tags from file like following image: I want to get description of an image file with poorly java code in 2 way: get image description with file and…
1 2 3
23
24