File Read/Write Help Please!

Hi,
I am trying to get my program to write an object (or just its varibles) to a file and then be able to read them out again and assign them to their title. i.e be able to read String bo, int car, and int[][] cost to a file (doesn't matter what as long as I can save it and then open it at a later date).
I really can not figure it out, but I will include my simple test code.
public class Bob//contains the stuff I want to save
     int car= 10;
     int cost[][]= {{1000,10},{1744,47733}};
     String bo = "Bob";
import java.io.*;
import java.util.*;
public class ObjectS
     public static void main(String args[])
          new ObjectS();
     public ObjectS()
          Bob abc = new Bob();
          try
          {//This code is most likely crud, so I really need help here.
               FileOutputStream out = new FileOutputStream("theTime");
               ObjectOutputStream s = new ObjectOutputStream(out);
               s.writeObject("Today");
               s.writeObject(abc);
               s.flush();
          catch(FileNotFoundException e){}
          catch(IOException e){}
}

It has already been pointed out that you need to use 'Serializable' and that you need to do more than just ignore exceptions. SO, to spell it out
public class Bob//contains the stuff I want to saveshould be
public class Bob implements Serializable //contains the stuff I want to save
int car= 10;
int cost[][]= {{1000,10},{1744,47733}};
String bo = "Bob";
import java.io.*;
import java.util.*;
public class ObjectS
public static void main(String args[])
new ObjectS();
public ObjectS()
Bob abc = new Bob();
try
{//This code is most likely crud, so I really need
help here.
FileOutputStream out = new
FileOutputStream("theTime");
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject("Today");
s.writeObject(abc);
s.flush();and this might be better as
s.close();
catch(FileNotFoundException e){}
catch(IOException e){}and these should do more than just ignore the exceptions! Exception are your freinds so as a very minimum you need something like
catch(FileNotFoundException e){
e.printStackTrace();
catch(IOException e){
e.printStackTrace();

Similar Messages

  • File read/write in Oracle JVM

    Are there any known issues around file read/write in Oracle JVM. I finally got around the issue of getting the error that says no permission is there by giving <<ALL FILES>> option, but still I don't see a file being created. Any help is appreciated.
    Code:
    try{
    fwriter = new PrintWriter(new FileOutputStream("debugLog.txt",true));
    } catch (IOException ioe) {
    System.err.println("IO Exception for Output File" + ioe.getMessage());
    Thanks.
    -Mujib

    A couple of suggestions:
    1. (Please don't be offended...) I assume you have some stuff like:
    fwriter.println("hello");
    fwriter.flush();
    fwriter.close();
    in your try block?
    2. Try catching FileNotFoundException and SecurityException also.
    3. Try providing a full path on the file just to make sure it's not buried somewhere odd.
    John H.

  • My Canon 5D Mark 3 camera..I cannot download Raw files using iPhoto help please

    Canon 5D Mark 3 I cannot download Raw file in iPhoto help please?

    You will need OS X 10.7.4 and iPhoto 11 or Aperture 3 for this.
    What do you have?

  • Missing file read/write feature on Mac OS X?

    HI,
    i am missing the file read/write statistics on Mac OS X. First i thought i just need to enable it in the template editor under "Advanced -> Java Application" but the two list items are simple not there. I ve seen a screenshot somewhere from the JMC where the two options are present but not for me. Can anyone tell me if this is a platform issue or how to enable it?
    Thx
    Marc

    You didn't say which version you are using, but I think what you are seeing is that the file and socket events are not available in JDK 8 only in JDK 7. This is a known regression that will be fixed in the next update to JDK 8.

  • Urgent!!! Need help in file read/write data to a serial port

    Hi,
    I really need someone's help in order for me to complete my project. I have attached a vi which I have taken from an example and integrate to my project. In the vi, I have managed to get the encoder counts using Ni 9411. I need to read/write that data from ni9411 to ni9870 without using any serial port as they are connected to a NI 9104 chasis. May I know whether I am correct in writing the data to my ni9870 port using the vi I have attached? Does anyone know how i can convert the number of counts to a 8-bit data/byte so that I can send the data through the RS232 port? I really need someone's help as I need to finished in 2 weeks time.
    I have also attached an vi on controlling the epos2 controller using instrument driver. Does anyone know how can i integrate this vi to the fpga vi (the one which I need to read/write data to 9870) as I need to send those data to control my epos2 controller.
    Please help me!!!
    Attachments:
    Encoder Position & Velocity (FPGA).vi ‏23 KB
    SINGLEMOTORMODIFIED.vi ‏17 KB

    Afai,
    As I allready suggested you here, call your local NI Office and ask for assistance!
    You really need assistence in a higher level that we can provide via the forums. Otherwise I don't see a chance for you to finish your project in time.
    1. Convert I32 to U8 to write it to the 9870 could be done like this:
    2. The vi to control the epos2.
    There is NO way ( absolutely NO way) to port this vi to FPGA. It's based on VISA calls, uses an event-structure, both are not available at the FPGA.
    The only thing you could do is to analyze the VI, the instruction set and design an FPGA vi which handles the specific instructions you would need.
    I have no experience with epos2 and I'm not 100% sure if this would work as you would like to use it. And doing this needs deep knowledge of LabVIEW, VISA, Instrument Drivers, the epos hardware, FPGA programming, and so on... 
    Christian

  • Getting file read/write/execute permissions.

    How can I get the read, write, and execute permissions for either a named file, or a File? I'm only interested in the permissions exposed to whatever user is running the VM.
    System.getSecurityManager() either returns null or some default SecurityManager that denies everything... I guess you have to set that explicitly, which doesn't really help me here.
    I've been browsing through the docs but I can't find anything that returns a FilePermission. It's highly possible that I missed something, though.
    Thanks in advance,
    Jason Cipriani
    [email protected]
    [email protected]

    Thanks for replying.
    That was the first thing I looked out. As it turns out, FilePermissions aren't for getting permissions on named files. Rather, they are for dealing out permissions that you set yourself, or representing permissions internally. If you look at the constructor for java.io.FilePermission, you'll see that, in addition to a file name (which, btw, can be anything since the constructor throws no IOException), you must also provide a list of permissions.
    So, unfortunately, that class can't take a file name and provide you with a permission list... it's just there for you to use to store permission information.
    That frustrates me a lot, because the name, FilePermissions, makes it seem like the most promising class to use for my application.
    Thanks, though,
    Jason.

  • Corrupted .rar file / incorrect password (help please)

    hi there,
    i have been sent several .rar video files and usually have no problem expanding them. i generally use Rar Expander and UnrarX. this time however, half-way through the expansion, it always stops, saying the password is incorrect or the file is corrupted. whilst it is being expanded i can watch the file up until the half-way point by locating it in finder. my mate has constantly tried uploading and sending me the file that seems to be corrupted but it's always the same issue. is there a way i can start the expansion after the corrupted file so i can see the other half of the file or expand each file individually. i also have VLC Rar Loader but for some reason I can't open this individual files in this either. please help, i would greatly appreciate.
    thanks in advance, ravi.

    Consecutive rar files cannot be opened individually. So if you have 10 .rar files, and the 5th one is broken, you can only view items in .rar files 1~4, and parts of 5 if you're lucky.
    Sorry, but that's how split compression works. You miiight be able to fix it using some special tool, but I don't know of any that works if the resulting file is supposed to be one giant video file.
    In all honesty, you would be better off re-downloading from their origins.

  • Blob for binary file, read/write problems

    Hi,
    I am relatively new to this type of development so apologies if this question is a bit basic.
    I am trying to write a binary document (.doc) to a blob and read it back again, constructing the original word file. I have the following code for reading and writing the file:
    private void save_addagreement_Click(object sender, EventArgs e)
    // Save the agreement to the database
    int test_setting = 0;
    // create an OracleConnection object to connect to the
    // database and open the connection
    string constr;
    if (test_setting == 0)
    constr = "User Id=royalty;Password=royalty;data source=xe";
    else
    constr = "User ID=lob_user;Password=lob_password;data source=xe";
    OracleConnection myOracleConnection = new OracleConnection(constr);
    myOracleConnection.Open();
    // create an OracleCommand object to hold a SQL statement
    OracleCommand myOracleCommand = myOracleConnection.CreateCommand();
    myOracleCommand.CommandText = "insert into blob_content(id, blob_column) values 2, empty_blob())";
    OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
    // step 2: read the row
    OracleTransaction myOracleTransaction = myOracleConnection.BeginTransaction();
    myOracleCommand.CommandText =
    "SELECT id, blob_column FROM blob_content WHERE id = 2";
    myOracleDataReader = myOracleCommand.ExecuteReader();
    myOracleDataReader.Read();
    Console.WriteLine("myOracleDataReadre[\"id\"] = " + myOracleDataReader["id"]);
    OracleBlob myOracleBlob = myOracleDataReader.GetOracleBlobForUpdate(1);
    Console.WriteLine("OracleBlob = " + myOracleBlob.Length);
    myOracleBlob.Erase();
    FileStream fs = new FileStream(agreement_filename.Text, FileMode.Open, FileAccess.Read);
    Console.WriteLine("Opened " + agreement_filename.Text + " for reading");
    int numBytesRead;
    byte[] byteArray = new byte[fs.Length];
    numBytesRead = fs.Read(byteArray, 0, (Int32)fs.Length);
    Console.WriteLine(numBytesRead + " read from file");
    myOracleBlob.Write(byteArray, 0, byteArray.Length);
    Console.WriteLine(byteArray.Length + " written to blob object");
    Console.WriteLine("Blob Length = " + myOracleBlob.Length);
    fs.Close();
    myOracleDataReader.Close();
    myOracleConnection.Close();
    This gives the following console output:
    myOracleDataReadre["id"] = 2
    OracleBlob = 0
    Opened D:\sample_files\oly_in.doc for reading
    56832 read from file
    56832 written to blob object
    Blob Length = 56832
    My write to file code is:
    private void save_agreement_to_disk_Click(object sender, EventArgs e)
    string filename;
    SaveFileDialog savedoc = new SaveFileDialog();
    if (savedoc.ShowDialog() == DialogResult.OK)
    filename = savedoc.FileName;
    // create an OracleConnection object to connect to the
    // database and open the connection
    OracleConnection myOracleConnection = new OracleConnection("User ID=royalty;Password=royalty");
    myOracleConnection.Open();
    // create an OracleCommand object to hold a SQL statement
    OracleCommand myOracleCommand = myOracleConnection.CreateCommand();
    myOracleCommand.CommandText =
    "SELECT id, blob_column " +
    "FROM blob_content " +
    "WHERE id = 2";
    OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
    myOracleDataReader.Read();
    Console.WriteLine("myOracleDataReader[id] = " + myOracleDataReader["id"]);
    //Step 2: Get the LOB locator
    OracleBlob myOracleBlob = myOracleDataReader.GetOracleBlobForUpdate(1);
    Console.WriteLine("Blob size = " + myOracleBlob.Length);
    //Step 3: get the BLOB data using the read() method
    byte[] byteArray = new byte[500];
    int numBytesRead;
    int totalBytes = 0;
    FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
    while ((numBytesRead = myOracleBlob.Read(byteArray, 0, 500)) > 0)
    totalBytes += numBytesRead;
    fs.Write(byteArray, 0, byteArray.Length);
    Console.WriteLine("numBytes = " + numBytesRead + " totalBytes = " + totalBytes);
    Console.WriteLine((int)fs.Length + " bytes written to file");
    fs.Close();
    myOracleDataReader.Close();
    myOracleConnection.Close();
    This gives the following console output:
    myOracleDataReader[id] = 2
    Blob size = 0
    0 bytes written to file
    If I manually add the blob file using the following:
    DECLARE
    my_blob BLOB;
    BEGIN
    -- load the BLOB
    my_bfile := BFILENAME('SAMPLE_FILES_DIR', 'binaryContent.doc');
    SELECT blob_column
    INTO my_blob
    FROM blob_content
    WHERE id = 1 FOR UPDATE;
    DBMS_LOB.FILEOPEN(my_bfile, dbms_lob.file_readonly);
    DBMS_LOB.LOADFROMFILE(my_blob, my_bfile, DBMS_LOB.GETLENGTH(my_bfile), 1, 1);
    DBMS_LOB.FILECLOSEALL();
    COMMIT;
    END;
    COMMIT;
    The write to file works perfectly. This tells me that there must be something wrong with my code that is writing the blob to the database. I tried where possible to following the Oracle article using large objects in .NET but that (along with most things on the internet) focus on uploading text files.
    Thanks in advance.
    Chris.

    myOracleCommand.CommandText = "insert into blob_content(id, blob_column) values 2, empty_blob())";
    OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
    This looks wrong, you shouldn't be using ExecuteReader unless you expect to get a result back. Try using ExecuteNonQuery to do the insert.

  • File read write

    Hi guys:
    its an easy question so i will explain as simply and as elborately as possible:
    i am reading from a file
    public void appendFile() {
        try {
          BufferedReader in = new BufferedReader(new FileReader("temp\\text.txt"));
          BufferedWriter out = new BufferedWriter(new FileWriter("temp\\text.txt", true));
          String str;
          String res;
          while ( (str = in.readLine()) != null) {
            res = process(str);
            if (res != null) {
              try {
                out.write(res);
                out.close();
              catch (IOException e) {
                log.info(e.toString());
          in.close();
        catch (IOException e) {
      }what i am trying to do is : read a file read though and where i get a certain string i replace it with another string :
    no looking at this code tell me if i will be writing at the same position or not.. i dont really remember if the cursor for readline and write line is the same :
    forexample : i read through ten lines and find the string i am looking for and i write at that moment witha new strinmg:
    1) will it write on the same line and write over the text that is already written
    OR
    2) will it write on the same line and move the text on that (that i am intending to replace) line to the next..
    OR
    3) will it write in the beginning of the file

    found the error i think : in FileWriter ("",true);
    the true defind that it hould be written in the end of file ... and not the begiining
    now i will see if the flase will write to the beginning or where the readline was done...

  • Can I batch change user access to folders & file read-write permissions?

    I had a corrupted user account on my iMac and after weeks of trying repairs I followed a forum suggestion to delete my account.
    Before doing so I synced all my document folders and files (since 2004) over my LAN to an external hard drive that was attached to my MacMini. I then deleted the iMac account.
    Next I backed up my Mac Mini user account with Time Machine. I then created a new iMac User account on the iMac and let the iMac access Time Machine to bring over all my MacMini preferences, settings, desktop, etc. I now have a fully functioning iMac user account.
    Here is the problem. I attached the USB external drive directly to my iMAC. I can access some of the folders and files on the external hard drive. Most of them refuse to let me acces the folder or open a file. If I use the GET INFO command I see an "_unknown" user with "read and write". I see an "everyone" with "no access". I can individually change each folder and file to allow my user account access and give myself permission to read and write the files. I cannot delete delete the "_unknown" account.
    It will take me days to individually change each folder and file manually like I am now doing.
    Is there a way to use Automator to add my user account to the folder or file and give me read and write folder and file permissions?
    Or is there any other way to do this in a batch change?
    Is there something I need to do to the external files right now that will ensure that I can access them if either computer crashes and I need to replace the MAC? I would hate to have to go through this again. Would having a MAC server instead of an external drive solve this?
    I am using MAC OS 10.6.8 with the most recent updates installed (as of today).
    Thanks,
    Sandi Dickenson

    Select the icon of the external drive in the sidebar of a Finder window, and open the Info window. In the "Sharing & Permissions" section of the window, click the lock icon and authenticate. Make sure you have read & write access to the volume by changing the settings if necessary. Then, from the action menu (gear icon), select "Apply to enclosed items."
    The "_unknown" user and group are assigned automatically to files on a volume with the "Ignore permissions" option set.

  • Have just work a load of Raw files as previous but they have saved as Video clips + JPG and turn all other CR2 files to video Help Please

    Have just worked a load of Raw Photo Files in Photoshop as on previous occasions but this time they have saved as VIDEO + JPG, also turned all other CR2 files into video in the folder. Can anybody help please.

    This forum is for discussions about downloading and installing Adobe software.  You need to find the forum that discusses using whichever software you are trying to use.
    Here is a link to a page that has links to all Adobe forums...
    Forum links page:
    https://forums.adobe.com/welcome

  • Cannot read discs, help please?

    Hi, any suggestions would be wonderful, but this is the current case:
    I have an iMac that I purchased back in 2007. Literally, I just installed snow leopard a week ago, and the next time I inserted a disc into my drive - the disc got stuck. And this was very bad of me, but I took a card and gently jimmied the disc till it came out. I have never had this problem till I installed snow leopard onto it. So now whenever I put a disc in - it doesn't mount, and I hear the drives trying to read the disc, but it only spits out the disc after thirty seconds or so. Also, I have tried many different discs, and it is all the same case. They are all spit out. Help please? Should I just take it into the Apple Store?

    While you might have damaged the drive, but because of how they are vertically mounted in the iMac and maybe some heat related issue, the drive could've simply just failed. Its time has come.
    Tthe internal optical drives in the aluminum style iMacs because of there mounting position seem to be prone to failure.
    Your AppleCare has long since expired.
    You have two options. You can pay to have the drive removed and replaced with a new internal drive and risk another premature failure. At least your iMac will have a brand new internal optical drive.
    OR forget about the internal drive and look for and purchase an external third party optical drive that will be much better built and last longer and you can use this drive again when and if you decide to upgrade to a newer Mac or iMac model.
    Another note. If you decide to have an Apple tech replace the internal optical drive, you might ask if possible, how much to install a larger hard drive into this iMac since they have to tear down the entire iMac anyhow.
    Good Luck on whichever decision you choose

  • Help with best solution for file read/write in web app (not local files)

    Problem in a nutshell...
    I have an AIR app to process images..  organize and add information. This information is read and written to local XML files. This is working fine (if still a be messy... still learning this OOP stuff ;O)
    So... now I am developing my Web gallery app to consume these files for a web gallery (unique concept huh? ;O)
    Reading them in was easy with the Declaration block....
    <fx:Declarations>
    <fx:XML id="galleryXML" source="gaXML.xml"/>
    <fx:XML id="baXML" source="baXML.xml"/>
    <fx:XML id="prjXML" source="prjXML.xml"/>
    <s:XMLListCollection id="galleryList" source="{galleryXML.item}"/>
    <s:XMLListCollection id="baList" source="{baXML.item}"/>
    </fx:Declarations>
    But I want the owner to have a maintenance mode where information can be added/changed and saved back to the XML file on the server. I have read about all the different services available, but I am not that familiar with them. Also I will have no way of knowing what services the user will have available on their host. So... help me out in understanding what the most universal solution would be to be able to read and write XML files stored on the host along with the application.
    I hope that is clear enough, but ask away if any more details will help in the discussion.
    Thanks
    Bob Galka

    Hi Jeba,
    Whenever u are using *"Thread.currentThread().getContextClassLoader()"* Code inside your application means the Files (Resources) which you are looking right now must be poresent in the CLASSPATH...(Bootstrap classloader/ System ClassLoader/ Application ClassLoader/ Sub Module ClassLoader...).
    So when we place a resource (example XML or Properties file) inside the "WEB-INF/classes" directory then it means that file (resource) is available as part of the Module Classloader....So the above code getContextClassloader() will be able to find that resource easily.
    Thanks
    jay SenSharma
    http://middlewaremagic.com/weblogic (Middleware Magic Is Here)

  • Error while relocating (Can't write file (no space)) - Help please

    I have been having trouble relocating master files since upgrading to Leopard. The problem doesn't seem to affect only Aperture. I can happen when using Finder or another application to move files from one drive to another. Other types of files don't seem to be affected, just my library of image files.
    The copy operation runs for a while then hangs up. The application doing the copy reports an error that that's the end. Aperture gives this error message: Error while relocating (Can’t write file (no space)). The Finder reports plenty of available space on the destination drive!
    I remember seeing a thread--but can't find it now--about a problem with certain xmp metatdata embedded into files causing problems with file operations.
    Hoping for a solution!
    Message was edited by: thomas80205

    It's possible that you might have a corrupt file. Have you tried to copy different files on to the destination drive? If those files copy fine, then narrow down the offending file by copying less images at a time.

  • File Read/Write Question

    Hello Everyone, nice to see a large Flex user group.
    I am a beginner to flex and I have a simple question. I am
    currently writing a web application in Flex. I compute some data
    and all I want to do is take this string and write it to a file on
    the local disk. In other words, writing some data to a location on
    the disk. Please note that this is a web application. I did some
    searching and could not find anything that works...since it is a
    flex web application they have some tight security. I am guessing
    we might need some help from javascript or something but do not
    know how to do that. If anyone could help me with this it would be
    really helpful. Thanks.

    This is correct - web apps cannot write to the local disk.
    Imagine you went to a web site that has a banner SWF and that SWF
    was written to open a file on your disk and fill up your disk
    drive. Or perhaps worse, the SWF opens a file and reads your
    personal and financial information. You just cannot be sure what is
    going to happen when you visit a web site. So we made the Flash
    Player as secure as possible and removed the ability to read or
    write local files.
    AIR, on the other hand, does not have that restriction. So
    you might want to look into that if writing to the local disk is
    important.

Maybe you are looking for

  • ADF 11g SelectOrdershuttle editing the items...

    Hi, I am using selectordershuttle compenent to display the User levels on the adf 11g page. How can i edit and delete the values which are in the shuttle component? Thanks in advance. CM

  • How does the VCA-DCV online exam work? What happens if I got disconnected?

    Hello guys, How does the online exam work? What happens if I my internet got disconnected in the middle of the exam? Does it pause / can I resume it later? Or is it gone forever and I am considered as "failed" ?

  • Table for this requirement

    Dear Cons      In a service p.o we have given service qty. as 10 ea & price 100/- inr . we want in which table this data is going to store. Also for Text entered in the doc. Header , for this we want to know in which table it will available. thanks n

  • IPod player auto launches without user action?

    My iphone 3G seems to launch the ipod music player without me calling up the application. Quite often my ipod will start playing on the home screen even though i have not launched it or attempt to start it. It's wired. I will just look at the phone o

  • Register an already registered server pool

    Hi, I reinstalled the OracleVM manager (v. 2.1.1) and i lost all data about old registered servers and vm's. The OracleVM Server is running ok, and also the vm on it. But I can't manage them because when i try to add the server pool it through an err