What is the Java function that is similar to file_get_contents in PHP?

by on June 7, 2011

Q: What is Java’s file_get_contents command?

PHP has a way of opening a file for input which creates a handle to the file and locks the file’s access to just that handle and just that instance. PHP also has an instant way called file_get_contents, which does a “virtual file load” and loads the raw data as a string value.

Im developing a Java chat room using a text file which a precoded maximum length slightly below the true potential available.

I ran a simple applet that every 5 seconds, loaded the text of a file into a textfield. It worked fine. I then wanted to use notepad to simulate someone else sending a message. I typed data, clicked save, and notepad said the file access was denied. Considering the sheer speed of Java and the extremely remote probability that I clicked save just as the textfield was being updated, I think i did something wrong. I did make sure the file access was closed immediately after extracting all file contents line by line. Please help is there a more efficient way to do this? If i get the job at the bank, there will be millions of people trying to access one of a few databases at any given time. If 2 clients feeding off the same file every 5 seconds fails, how can I hope to share access globally? This chat program is the masterpeice of mine before I apply for the job. thanks in advance for your help. 🙂


One Response to “What is the Java function that is similar to file_get_contents in PHP?”
  1.  
    Picked as best answer

    See this Java tutorial on Basic I/O

    http://download.oracle.com/javase/tutorial/essential/io/

    You might like the other official java tutorials as well.