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

How to write a file with variable "key" and its position?

I would like to write indexed file (indexed.ind), and I need two variables. One variable is "key" witch is written in file.dat, the other variable is "position", that should be the position where "key" is written in file.dat. Here is my code, but…
Amaro88
  • 1
  • 2
0
votes
0 answers

How to interrelated the atributtes when the file is read? RandomAccessFile readingUTF();

Hi when I read the file with readUTF() method, the console output displays the atributtes separately. For example, I have this code: public void grabarFichero(String clave, String nombre, String edad, String sueldo) { int i; String datos[] =…
Amaro88
  • 1
  • 2
0
votes
1 answer

EncryptedRandomAccessFile

Is there anything like an EncryptedRandomAccessFile in Java? That's how I'd call it, but the name seems to be too innovative as I couldn't find anything. Basically, it should implement DataInput, DataOutput1 and provide a seek method. I guess, all…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
0
votes
1 answer

NullPointerException using RandomAccesssFile at seek

I want to introduce information about cars and keep it in a file. My problem is that when I introduce datas it show me has occurred a NullPointerException where I use "seek" to place the pointer where I want. I have a Java Class that I use to ask…
Noneking
  • 11
  • 1
0
votes
3 answers

End line StringBuilder in RandomAccessFile

I'm trying use the class RandomAccessFile, but I have a problem with the Strings. This is the first part. Write in a File: public static void main(String[] args) throws IOException { File file = new File("/home/pep/java/randomFile.dat"); …
0
votes
2 answers

Troubles Finishing First Assignment - Python

I'm doing my first programming course and I'm stuck already. I'm trying to make a program that will tell you how many toy's you can make given how many pieces the user has. To create the toy, you need to have 5 upper pieces and 2 lower pieces. I've…
AmandaZ
  • 3
  • 2
0
votes
2 answers

java String comparison interesting bug

I have an intersting bug where program hit this line System.out.println("!tempLine.equals(raf.readLine().toString())"); every time at a random index in the loop. Not sure how is it possible that tempLine does not equal raf.readLine().toString()…
user3628777
  • 529
  • 3
  • 10
  • 20
0
votes
2 answers

Creating a new String using a byte array is giving a strange result

I am reading a file using the readFully method of RandomAccessFile class, but the results are not what I exactly expected. This is the simple function which reads the file and returns a new String using the byte array where all the bytes are…
nbro
  • 15,395
  • 32
  • 113
  • 196
0
votes
0 answers

Java: Updating random access file: how?

I'm currently working on a random access file and I need to have an update method. This method deletes a record and replace it with a new record. I'm wondering how could I do that method.. I am required to use random access file.. but if there's…
0
votes
1 answer

Java readFully as int[]

I have a RandomAccessFile fileA, of size 4*k which has been made by using something like the DataOutputStream.writeInt() method. I wish to read it fully into an array int[k]. What is the fastest method to do it? I have considered DataInputStream…
Dangercrow
  • 145
  • 1
  • 11
0
votes
0 answers

readUTF in random access file complications

I'm on with this problem for a week now..and i can't find what's really wrong with this. I'm comparing 2 strings. First is from a user input then the second is from the random access file read. the first string is a password converted to string and…
0
votes
0 answers

Moving some lines back in Java Buffer Reader Loop (Re-reading) based on a condition

I am reading a 15 Million file using Java BUfferReader. In some conditions, I have to loop back 1000 lines in the buffer and RE-READ them, and then continuing them with the next records after those 1000. In simple words I want to be able to have…
Noman K
  • 277
  • 1
  • 5
  • 15
0
votes
1 answer

Does a variable type struct need to be an array to store 100 elements?

I am new here so sorry for any misunderstanding. I am learning Random Access File on C Language. And I am confused about the variable blankClient. It is not an array, but how could Deitel (the author) initialize 100 blanks record using blank…
Khoily
  • 17
  • 3
0
votes
0 answers

Using Java change content of text file

There is a text file like this: abcd 1234 and the code I am using : RandomAccessFile file = null; try { file = new RandomAccessFile("C:\\Users\\z36137zz\\Desktop\\test.txt", "rw"); file.writeBytes("edcba\n"); …
huashui
  • 1,758
  • 2
  • 16
  • 24
0
votes
1 answer

Where to add the directory to save the downloaded files? Java

I have a program which will download files from a specific URL and save them inside the default directory where .java files are stored. However, I want to set a specific location to store the downloaded files. String locID =…