Writing to file limiting system performanc​e

Hello,
I really could use some help with my VI in terms of writing data.  I’ve had a LOT of help optimizing my code and am trying to enhance the performance in terms of data acquisition.  However, it seems as though writing to a data file is really limiting the frequency I can sample at.  I’ve done some research and understand that writing data at every iteration of the while loop and the build array function slows things down.  How would I modify the code so that the array buffer would store maybe 5000 data points before writing to a file, then clearing the array?  That would keep the array size small, as well as reduce the number of times the program is performing the write to file function.  Is there a better way of doing this?  I’m open to any other ideas as well.    
I am taking data from 14 channels, and would like to sample at 1 kHz each.  The task right now is created within Measurement and Automation Explorer, and the number of samples is at 100.  I also use a buffer indicator, which will generally grow out of control, no matter how much I modify the number of samples and the frequency.  The length of my test can last upwards to 6 hours, so it needs to work that long without crashing.     
The code and attached subVI’s is attached.  Hopefully it's all there.
Thanks for your help,
Alex
Attachments:
Test Program.zip ‏295 KB

Lynn,
Yea, I'll have to keep on the block diagram size in the future.  Can get unwieldy.
I tried incorporating the Recent History Buffer example into my code.  I did have a few hang ups, which are giving me some trouble.  Mostly, how do I connect my waveform data to the Buffer VI?  Will I be able to have all my channels connect to this?  Also, ultimately I will have two write to file VI's.  Can the buffer differentiate between which file to write?
Thanks,
Alex
Attachments:
Instrument Panel V1.1 (Labview 8.0).vi ‏159 KB

Similar Messages

  • Proxy Server in File Transfer System

    Hi, I need to write out a file transfer system through a proxy server for my project
    All the while i was writing a file transfer system directly from client to server without any security issue
    Anyway, the scope is given as below, and i know it needs the JSSE package to come out a SSLSocket and SSLServerSocket.
    The question is...
    1. can i use NIO with JSSE included?
    2. how to come out a java proxy server? is there any tutorial i can read through?
    The scope is given as below
    1) Proxy server
    * perform tunning and keep the linking between file transfer host and client
    * authenticate the file transfer client using CA certificate to establish SSL connection
    * Once authorised, need to establish another SSL connection to host engine
    2) File Transfer Manager at Client
    * To initiate SSL connection to proxy server
    * To open two type of connection: command and file connection
    * The command connection is always keep alive
    * For the file connection, the system required to re-open another connection after send file to host
    * Auto-reconnect to server when the connection is down
    * Re-handshake the SSL connection when the channel is inactive for sometime
    3) File Transfer Manager at host
    * To authenticate the proxy server and authorise the client before establish the connection
    * Manage the connection
    * request to client to open new connection (by sending command) when there is no file connection available to send file to client
    * Request for re-handshake the SSL connection when the channel is inactive for sometime

    Hi,
    It is a new feature of SMB3 named SMB MultiChannel, which helps copy files through multiple NICs. 
    Detailed information please see:
    http://blogs.technet.com/b/josebda/archive/2012/05/13/the-basics-of-smb-multichannel-a-feature-of-windows-server-2012-and-smb-3-0.aspx
    As mentioned you can disable or enable it with following steps:
    2.2. Disabling
    SMB Multichannel is enabled by default and there is typically no need to disable it. 
    However, if you want to disable SMB Multichannel (for testing purposes, for instance), you can use the following PowerShell cmdlets:
    On the SMB server side:
    Set-SmbServerConfiguration -EnableMultiChannel $false
    On the SMB client side:
    Set-SmbClientConfiguration -EnableMultiChannel $false
    Note: Disabling the feature on either the client or the server prevent the systems from using it.
    2.3. Re-enabling
    You can re-enable SMB Multichannel after you disabled it by using:
    On the SMB server side:
    Set-SmbServerConfiguration -EnableMultiChannel $true
    On the SMB client side:
    Set-SmbClientConfiguration -EnableMultiChannel $true
    Note: You need to enable the feature on both the client or the server to start using it again.
    If you have any feedback on our support, please send to [email protected]

  • Access denied error while writing a file to the file system - myfileupload.saveas() throws system.unauthorizedexception

    hi,
    as part of my requirement , i have to perform read and  write  operations of  few files [ using the file upload control in my custom visual web part] and on submit button click.
    but while writing these files - with the help of  fileupload control - and when i use  myfileupload.saveas(mylocation);
    - i am saving these files into my D:\ drive of my server , where i am executing my code -, am getting access denied error.
    it throws system.unauthorizedexception.
    i have given full control on that folder where i was trying to store my attached files. and also  after following asp.net forums,
    i have added  iusr group added and performed all those steps such that, the file is saved in my D:\ drive.
    but unfortunately  that didnt happen.
    also
    a) i am trying the code with runwithelevatedprivileges(delegate() )  code
    b) shared the drive within the  d :drive where i want o save the files.
    c) given the full privieleges for the app pool identity- in my case , its
    network service.
    the  other strange thing is that, the same code works perfectly in  other machine, where the same sp, vs 2012  etc were installed .
    would like to know, any other changes/ steps i need to make it on this  server, where i am getting the  error.
    help is  appreciated!

    vishnuS1984 wrote:
    Hi Friends,
    I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class...So let's see... C:\GetMe1 is a directory on your machine, right? And this is what you are doing with that directory:
    public static void copyFiles(File src, File dest) throws IOException
    // dest is a 'File' object but represents the C:\GetMe1 directory, right?
    fout = new FileOutputStream (dest);If it's a directory, where in your code are you appending the source file name to the path, before trying to open an output stream on it? You're not.
    BTW, this is awful:
    catch (IOException e)
    IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
    src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
    wrapper.initCause(e);
    wrapper.setStackTrace(e.getStackTrace());
    throw wrapper;
    }1) You're hiding the original IOException and replacing it with your own? For what good purpose?
    2) Even if you had a good reason to do that, this would be simpler and better:
    throw new IOException("your custom message goes here", e);
    rather than explicitly invokign initCause and setStackTrace. Yuck!

  • Page fault in nipalk.sys when writing large file , system crashes

    When reading from VXI 2211 and writing to a file the system crashes with a page fault error in nipalk.sys. I tried loading new drivers for VISA, VXI, even DAQ which I don't use. Where does nipalk.sys come from??

    jcnoble wrote:
    > When reading from VXI 2211 and writing to a file the system crashes
    > with a page fault error in nipalk.sys. I tried loading new drivers for
    > VISA, VXI, even DAQ which I don't use. Where does nipalk.sys come
    > from??
    This is the low level device driver used by all NI hardware device
    drivers. PAL stands most probably for Platform Abstraction Layer and
    what that means it is providing an uniform device driver API for
    managing memory, IO addresses, DMA channels and Interrupts. Most
    probably this NIPAL device driver API is almost the same on all
    platforms NI develops modern hardware drivers for. This allows easier
    porting of device drivers to new hardware as the big work for porting a
    hardware driver is about porting this NIPAL device driver.
    I
    would not think that disk writing is the real culprit here, but it may
    trigger a problem occuring earlier during VXI access.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Writing to a unix system file

    I need to write to a unix config file using Java, so I'm basically trying to do what sudo normally does. What is the proper way to pass the credentials and write to the file in Java?
    This will be for a desktop application, so I'll be getting the sudo password from a swing element and then authenticating to allow writing a file.

    You'll have to Runtime.exec sudo or a script that does sudo. You can't just directly have your Java code switch the identity of who's executing it midstream.

  • 2GB OR NOT 2GB - FILE LIMITS IN ORACLE

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-11
    2GB OR NOT 2GB - FILE LIMITS IN ORACLE
    ======================================
    Introduction
    ~~~~~~~~~~~~
    This article describes "2Gb" issues. It gives information on why 2Gb
    is a magical number and outlines the issues you need to know about if
    you are considering using Oracle with files larger than 2Gb in size.
    It also
    looks at some other file related limits and issues.
    The article has a Unix bias as this is where most of the 2Gb issues
    arise but there is information relevant to other (non-unix)
    platforms.
    Articles giving port specific limits are listed in the last section.
    Topics covered include:
    Why is 2Gb a Special Number ?
    Why use 2Gb+ Datafiles ?
    Export and 2Gb
    SQL*Loader and 2Gb
    Oracle and other 2Gb issues
    Port Specific Information on "Large Files"
    Why is 2Gb a Special Number ?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Many CPU's and system call interfaces (API's) in use today use a word
    size of 32 bits. This word size imposes limits on many operations.
    In many cases the standard API's for file operations use a 32-bit signed
    word to represent both file size and current position within a file (byte
    displacement). A 'signed' 32bit word uses the top most bit as a sign
    indicator leaving only 31 bits to represent the actual value (positive or
    negative). In hexadecimal the largest positive number that can be
    represented in in 31 bits is 0x7FFFFFFF , which is +2147483647 decimal.
    This is ONE less than 2Gb.
    Files of 2Gb or more are generally known as 'large files'. As one might
    expect problems can start to surface once you try to use the number
    2147483648 or higher in a 32bit environment. To overcome this problem
    recent versions of operating systems have defined new system calls which
    typically use 64-bit addressing for file sizes and offsets. Recent Oracle
    releases make use of these new interfaces but there are a number of issues
    one should be aware of before deciding to use 'large files'.
    What does this mean when using Oracle ?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The 32bit issue affects Oracle in a number of ways. In order to use large
    files you need to have:
    1. An operating system that supports 2Gb+ files or raw devices
    2. An operating system which has an API to support I/O on 2Gb+ files
    3. A version of Oracle which uses this API
    Today most platforms support large files and have 64bit APIs for such
    files.
    Releases of Oracle from 7.3 onwards usually make use of these 64bit APIs
    but the situation is very dependent on platform, operating system version
    and the Oracle version. In some cases 'large file' support is present by
    default, while in other cases a special patch may be required.
    At the time of writing there are some tools within Oracle which have not
    been updated to use the new API's, most notably tools like EXPORT and
    SQL*LOADER, but again the exact situation is platform and version specific.
    Why use 2Gb+ Datafiles ?
    ~~~~~~~~~~~~~~~~~~~~~~~~
    In this section we will try to summarise the advantages and disadvantages
    of using "large" files / devices for Oracle datafiles:
    Advantages of files larger than 2Gb:
    On most platforms Oracle7 supports up to 1022 datafiles.
    With files < 2Gb this limits the database size to less than 2044Gb.
    This is not an issue with Oracle8 which supports many more files.
    In reality the maximum database size would be less than 2044Gb due
    to maintaining separate data in separate tablespaces. Some of these
    may be much less than 2Gb in size.
    Less files to manage for smaller databases.
    Less file handle resources required
    Disadvantages of files larger than 2Gb:
    The unit of recovery is larger. A 2Gb file may take between 15 minutes
    and 1 hour to backup / restore depending on the backup media and
    disk speeds. An 8Gb file may take 4 times as long.
    Parallelism of backup / recovery operations may be impacted.
    There may be platform specific limitations - Eg: Asynchronous IO
    operations may be serialised above the 2Gb mark.
    As handling of files above 2Gb may need patches, special configuration
    etc.. there is an increased risk involved as opposed to smaller files.
    Eg: On certain AIX releases Asynchronous IO serialises above 2Gb.
    Important points if using files >= 2Gb
    Check with the OS Vendor to determine if large files are supported
    and how to configure for them.
    Check with the OS Vendor what the maximum file size actually is.
    Check with Oracle support if any patches or limitations apply
    on your platform , OS version and Oracle version.
    Remember to check again if you are considering upgrading either
    Oracle or the OS in case any patches are required in the release
    you are moving to.
    Make sure any operating system limits are set correctly to allow
    access to large files for all users.
    Make sure any backup scripts can also cope with large files.
    Note that there is still a limit to the maximum file size you
    can use for datafiles above 2Gb in size. The exact limit depends
    on the DB_BLOCK_SIZE of the database and the platform. On most
    platforms (Unix, NT, VMS) the limit on file size is around
    4194302*DB_BLOCK_SIZE.
    Important notes generally
    Be careful when allowing files to automatically resize. It is
    sensible to always limit the MAXSIZE for AUTOEXTEND files to less
    than 2Gb if not using 'large files', and to a sensible limit
    otherwise. Note that due to <Bug:568232> it is possible to specify
    an value of MAXSIZE larger than Oracle can cope with which may
    result in internal errors after the resize occurs. (Errors
    typically include ORA-600 [3292])
    On many platforms Oracle datafiles have an additional header
    block at the start of the file so creating a file of 2Gb actually
    requires slightly more than 2Gb of disk space. On Unix platforms
    the additional header for datafiles is usually DB_BLOCK_SIZE bytes
    but may be larger when creating datafiles on raw devices.
    2Gb related Oracle Errors:
    These are a few of the errors which may occur when a 2Gb limit
    is present. They are not in any particular order.
    ORA-01119 Error in creating datafile xxxx
    ORA-27044 unable to write header block of file
    SVR4 Error: 22: Invalid argument
    ORA-19502 write error on file 'filename', blockno x (blocksize=nn)
    ORA-27070 skgfdisp: async read/write failed
    ORA-02237 invalid file size
    KCF:write/open error dba=xxxxxx block=xxxx online=xxxx file=xxxxxxxx
    file limit exceed.
    Unix error 27, EFBIG
    Export and 2Gb
    ~~~~~~~~~~~~~~
    2Gb Export File Size
    ~~~~~~~~~~~~~~~~~~~~
    At the time of writing most versions of export use the default file
    open API when creating an export file. This means that on many platforms
    it is impossible to export a file of 2Gb or larger to a file system file.
    There are several options available to overcome 2Gb file limits with
    export such as:
    - It is generally possible to write an export > 2Gb to a raw device.
    Obviously the raw device has to be large enough to fit the entire
    export into it.
    - By exporting to a named pipe (on Unix) one can compress, zip or
    split up the output.
    See: "Quick Reference to Exporting >2Gb on Unix" <Note:30528.1>
    - One can export to tape (on most platforms)
    See "Exporting to tape on Unix systems" <Note:30428.1>
    (This article also describes in detail how to export to
    a unix pipe, remote shell etc..)
    Other 2Gb Export Issues
    ~~~~~~~~~~~~~~~~~~~~~~~
    Oracle has a maximum extent size of 2Gb. Unfortunately there is a problem
    with EXPORT on many releases of Oracle such that if you export a large table
    and specify COMPRESS=Y then it is possible for the NEXT storage clause
    of the statement in the EXPORT file to contain a size above 2Gb. This
    will cause import to fail even if IGNORE=Y is specified at import time.
    This issue is reported in <Bug:708790> and is alerted in <Note:62436.1>
    An export will typically report errors like this when it hits a 2Gb
    limit:
    . . exporting table BIGEXPORT
    EXP-00015: error on row 10660 of table BIGEXPORT,
    column MYCOL, datatype 96
    EXP-00002: error in writing to export file
    EXP-00002: error in writing to export file
    EXP-00000: Export terminated unsuccessfully
    There is a secondary issue reported in <Bug:185855> which indicates that
    a full database export generates a CREATE TABLESPACE command with the
    file size specified in BYTES. If the filesize is above 2Gb this may
    cause an ORA-2237 error when attempting to create the file on IMPORT.
    This issue can be worked around be creating the tablespace prior to
    importing by specifying the file size in 'M' instead of in bytes.
    <Bug:490837> indicates a similar problem.
    Export to Tape
    ~~~~~~~~~~~~~~
    The VOLSIZE parameter for export is limited to values less that 4Gb.
    On some platforms may be only 2Gb.
    This is corrected in Oracle 8i. <Bug:490190> describes this problem.
    SQL*Loader and 2Gb
    ~~~~~~~~~~~~~~~~~~
    Typically SQL*Loader will error when it attempts to open an input
    file larger than 2Gb with an error of the form:
    SQL*Loader-500: Unable to open file (bigfile.dat)
    SVR4 Error: 79: Value too large for defined data type
    The examples in <Note:30528.1> can be modified to for use with SQL*Loader
    for large input data files.
    Oracle 8.0.6 provides large file support for discard and log files in
    SQL*Loader but the maximum input data file size still varies between
    platforms. See <Bug:948460> for details of the input file limit.
    <Bug:749600> covers the maximum discard file size.
    Oracle and other 2Gb issues
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This sections lists miscellaneous 2Gb issues:
    - From Oracle 8.0.5 onwards 64bit releases are available on most platforms.
    An extract from the 8.0.5 README file introduces these - see <Note:62252.1>
    - DBV (the database verification file program) may not be able to scan
    datafiles larger than 2Gb reporting "DBV-100".
    This is reported in <Bug:710888>
    - "DATAFILE ... SIZE xxxxxx" clauses of SQL commands in Oracle must be
    specified in 'M' or 'K' to create files larger than 2Gb otherwise the
    error "ORA-02237: invalid file size" is reported. This is documented
    in <Bug:185855>.
    - Tablespace quotas cannot exceed 2Gb on releases before Oracle 7.3.4.
    Eg: ALTER USER <username> QUOTA 2500M ON <tablespacename>
    reports
    ORA-2187: invalid quota specification.
    This is documented in <Bug:425831>.
    The workaround is to grant users UNLIMITED TABLESPACE privilege if they
    need a quota above 2Gb.
    - Tools which spool output may error if the spool file reaches 2Gb in size.
    Eg: sqlplus spool output.
    - Certain 'core' functions in Oracle tools do not support large files -
    See <Bug:749600> which is fixed in Oracle 8.0.6 and 8.1.6.
    Note that this fix is NOT in Oracle 8.1.5 nor in any patch set.
    Even with this fix there may still be large file restrictions as not
    all code uses these 'core' functions.
    Note though that <Bug:749600> covers CORE functions - some areas of code
    may still have problems.
    Eg: CORE is not used for SQL*Loader input file I/O
    - The UTL_FILE package uses the 'core' functions mentioned above and so is
    limited by 2Gb restrictions Oracle releases which do not contain this fix.
    <Package:UTL_FILE> is a PL/SQL package which allows file IO from within
    PL/SQL.
    Port Specific Information on "Large Files"
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Below are references to information on large file support for specific
    platforms. Although every effort is made to keep the information in
    these articles up-to-date it is still advisable to carefully test any
    operation which reads or writes from / to large files:
    Platform See
    ~~~~~~~~ ~~~
    AIX (RS6000 / SP) <Note:60888.1>
    HP <Note:62407.1>
    Digital Unix <Note:62426.1>
    Sequent PTX <Note:62415.1>
    Sun Solaris <Note:62409.1>
    Windows NT Maximum 4Gb files on FAT
    Theoretical 16Tb on NTFS
    ** See <Note:67421.1> before using large files
    on NT with Oracle8
    *2 There is a problem with DBVERIFY on 8.1.6
    See <Bug:1372172>

    I'm not aware of a packaged PL/SQL solution for this in Oracle 8.1.7.3 - however it is very easy to create such a program...
    Step 1
    Write a simple Java program like the one listed:
    import java.io.File;
    public class fileCheckUtl {
    public static int fileExists(String FileName) {
    File x = new File(FileName);
    if (x.exists())
    return 1;
    else return 0;
    public static void main (String args[]) {
    fileCheckUtl f = new fileCheckUtl();
    int i;
    i = f.fileExists(args[0]);
    System.out.println(i);
    Step 2 Load this into the Oracle data using LoadJava
    loadjava -verbose -resolve -user user/pw@db fileCheckUtl.java
    The output should be something like this:
    creating : source fileCheckUtl
    loading : source fileCheckUtl
    creating : fileCheckUtl
    resolving: source fileCheckUtl
    Step 3 - Create a PL/SQL wrapper for the Java Class:
    CREATE OR REPLACE FUNCTION FILE_CHECK_UTL (file_name IN VARCHAR2) RETURN NUMBER AS
    LANGUAGE JAVA
    NAME 'fileCheckUtl.fileExists(java.lang.String) return int';
    Step 4 Test it:
    SQL> select file_check_utl('f:\myjava\fileCheckUtl.java') from dual
    2 /
    FILE_CHECK_UTL('F:\MYJAVA\FILECHECKUTL.JAVA')
    1

  • Too many open files in system cause database goes down

    Hello experts I am very worry because of the following problems. I really hope you can help me.
    some server features
    OS: Suse Linux Enterprise 10
    RAM: 32 GB
    CPU: intel QUAD-CORE
    DB: There is 3 instances RAC databases (version 11.1.0.7) in the same host.
    Problem: The database instances begin to report Error message: Linux-x86_64 Error: 23: Too many open files in system
    and here you are other error messages:
    ORA-27505: IPC error destroying a port
    ORA-27300: OS system dependent operation:close failed with status: 9
    ORA-27301: OS failure message: Bad file descriptor
    ORA-27302: failure occurred at: skgxpdelpt1
    ORA-01115: IO error reading block from file 105 (block # 18845)
    ORA-01110: data file 105: '+DATOS/dac/datafile/auditoria.519.738586803'
    ORA-15081: failed to submit an I/O operation to a disk
    At the same time I search into the /var/log/messages as root user and I the error notice me the same problem:
    Feb 7 11:03:58 bls3-1-1 syslog-ng[3346]: Cannot open file /var/log/mail.err for
    writing (Too many open files in system)
    Feb 7 11:04:56 bls3-1-1 kernel: VFS: file-max limit 131072 reached
    Feb 7 11:05:05 bls3-1-1 kernel: oracle[12766]: segfault at fffffffffffffff0 rip
    0000000007c76323 rsp 00007fff466dc780 error 4
    I think I get clear about the cause, maybe I need to increase the fs.file-max kernel parameter but I do not know how to set a good value. Here you are my sysctl.conf file and the limits.conf file:
    sysctl.conf
    kernel.shmall = 2097152
    kernel.shmmax = 17179869184
    kernel.shmmni = 4096
    kernel.sem = 250 32000 100 128
    fs.file-max = 6553600
    net.ipv4.ip_local_port_range = 1024 65000
    net.core.rmem_default = 4194304
    net.core.rmem_max = 4194304
    net.core.wmem_default = 262144
    net.core.wmem_max = 4194304
    limits.conf
    oracle soft nproc 2047
    oracle hard nproc 16384
    oracle soft nofile 1024
    oracle hard nofile 65536

    process limit
    bcm@bcm-laptop:~$ ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 20
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 16382
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) unlimited
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited

  • New to Applets: Problems wiht writing to files and with scroll panes.

    Hi, I've recently graduated from university and so I have limited experience in java programming and I'm having some trouble with JApplets (this is the first time I've made one). I'm trying to make a simple program that will allow users to pick one of a few background images from a list (a list of jpanels within a scroll pane) then at the click of a button will output a CSS with the background tag set to the image location. This is for use on a microsoft sharepoint site where each user has a My-Sit area which I want to be customizable.
    So far I've been creating this program as an application rather than a JApplet and just having another class that extends the JApplet Class which then displays the JFrame from the GUI Class. This initially didnt work because I was trying to add a window to a container so I kept programming it as an application until I got it working before trying to convert it to a JApplet. I solved the previous problem by changing my GUI class to extend JPanel instead of JFrame and it now displays correctly but with a coupe of issues.
    Firstly the applet will not create/write to the CSS file. I read that applets couldnt read/write to the users file system but they could to their own. The file I wish to write to is kept on the same machine as the applet so I'm not sure why this isn't working.
    Secondly the scroll panel is no longer working properly. This worked fine when I was still running the program as an application when the GUI still extended JFrame instead of JPanel (incidentally the program no longer runs as an application in this state) but now the scroll bar does not appear. This is a problem since I want the applet to remain the same size on the page even if I decide to add more backgrounds to the list. I tried setting the applet height/width to smaller values in the html file to see if the scroll bar would appear if the area was smaller than the GUI should be, but this just meant the bottom off the applet was cut off.
    Could anyone offer any suggestion as to why these thigns arnt working and how to fix them? If necessary I can post my source code here. Thanks in advance.

    Ok, well my program is made up of 4 classes, I hope this isnt too much to be posting. If any explaination is needed then I'll post that next. Theres lots of print lines scattered aroudn due to me trying to fix this and theres some stuff commented out from when the program used to be an application isntead of an applet.
    GUI Class, this was the main class until I made a JApplet Class
    public class AppletGUI extends JPanel{
        *GUI Components*
        //JFrames
        JFrame mainGUIFrame = new JFrame();
        JFrame changeBackgroundFrame = new JFrame();
        //JPanels (Sub-panels are indented)
        JPanel changeBackgroundJP = new JPanel(new BorderLayout());
            JPanel changeBackgroundBottomJP = new JPanel(new GridLayout(1,2));
        JPanel backgroundJP = new JPanel(new GridLayout(1,2));
        JPanel selectBackground = new JPanel(new GridLayout(1,2));
        //Jbuttons
        JButton changeBackgroundJB = new JButton("Change Background");
        JButton defaultStyleJB = new JButton("Reset Style");
        //JLabels
        JLabel changeBackgroundJL = new JLabel("Choose a Background from the Menu");
        JLabel backgroundJL = new JLabel();
        //JScrollPane
        JScrollPane backgroundList = new JScrollPane();
            JPanel backgroundListPanel = new JPanel(new GridLayout());
        //Action Listeners
        ButtonListener bttnLstnr = new ButtonListener();
        //Controllers
        CSSGenerator cssGenerator = new CSSGenerator();
        Backgrounds backgroundsController = new Backgrounds();
        backgroundMouseListener bgMouseListener = new backgroundMouseListener();
        //Flags
        Component selectedComponent = null;
        *Colour Changer*
        //this method is used to change the colour of a selected JP
        //selected JPs have their background darkered and when a
        //different JP is selected the previously seleced JP has its
        //colour changed back to it's original.
        public void changeColour(JPanel theJPanel, boolean isDarker){
        //set selected JP to a different colour
        Color tempColor = theJPanel.getBackground();
            if(isDarker){
                tempColor = tempColor.darker();
            else{
                tempColor = tempColor.brighter();
            theJPanel.setBackground(tempColor);
         //also find any sub-JPs and change their colour to match
         int j = theJPanel.getComponents().length;
         for(int i = 0; i < j; i++){
                String componentType = theJPanel.getComponent(i).getClass().getSimpleName();
                if(componentType.equals("JPanel")){
                    theJPanel.getComponent(i).setBackground(tempColor);
        *Populating the GUI*
        //backgroundList.add();
        //Populating the Backgrounds List
        *Set Component Size Method*
        public void setComponentSize(Component component, int width, int height){
        Dimension tempSize = new Dimension(width, height);
        component.setSize(tempSize);
        component.setMinimumSize(tempSize);
        component.setPreferredSize(tempSize);
        component.setMaximumSize(tempSize);     
        *Constructor*
        public AppletGUI() {
            //REMOVED CODE
            //AppletGUI.setDefaultLookAndFeelDecorated(true);
            //Component Sizes
            //setComponentSize
            //Adding Action Listeners to Components
            System.out.println("adding actions listeners to components");
            changeBackgroundJB.addActionListener(bttnLstnr);
            defaultStyleJB.addActionListener(bttnLstnr);
            //Populating the Change Background Menu
            System.out.println("Populating the window");
            backgroundsController.populateBackgroundsData();
            backgroundsController.populateBackgroundsList();
            //loops to add background panels to the JSP
            ArrayList<JPanel> tempBackgroundsList = new ArrayList<JPanel>();
            JPanel tempBGJP = new JPanel();
            tempBackgroundsList = backgroundsController.getBackgroundsList();
            int j = tempBackgroundsList.size();
            JPanel backgroundListPanel = new JPanel(new GridLayout(j,1));
            for(int i = 0; i < j; i++){
                tempBGJP = tempBackgroundsList.get(i);
                System.out.println("Adding to the JSP: " + tempBGJP.getName());
                //Add Mouse Listener
                tempBGJP.addMouseListener(bgMouseListener);
                backgroundListPanel.add(tempBGJP, i);
            //set viewpoing
            backgroundList.setViewportView(backgroundListPanel);
            /*TESTING
            System.out.println("\n\n TESTING!\n Printing Content of SCROLL PANE \n");
            j = tempBackgroundsList.size();
            for(int i = 0; i < j; i++){
                System.out.println(backgroundList.getComponent(i).getName());
            changeBackgroundJP.add(changeBackgroundJL, BorderLayout.NORTH);
            changeBackgroundJP.add(backgroundList, BorderLayout.CENTER);
            //changeBackgroundJP.add(tempBGJP, BorderLayout.CENTER);
            changeBackgroundJP.add(changeBackgroundBottomJP, BorderLayout.SOUTH);
            changeBackgroundBottomJP.add(changeBackgroundJB);
            changeBackgroundBottomJP.add(defaultStyleJB);
            System.out.println("Finsihed populating");
            //REMOVED CODE
            //adding the Background Menu to the GUI and settign the GUI options
            //AppletGUI.setDefaultLookAndFeelDecorated(true);
            //this.setResizable(true);
            //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocation(500,500);
            this.setSize(400,300);
            this.add(changeBackgroundJP);
        //REMOVED CODE
         *Main Method*
        public static void main(String[] args){
           System.out.println("Creating GUI");
           AppletGUI theGUI = new AppletGUI();
           theGUI.setVisible(true);
           System.out.println("GUI Displayed");
         *Button Listener Inner Class*
        public class ButtonListener implements ActionListener{
            //check which button is clicked
            public void actionPerformed(ActionEvent event) {
                AbstractButton theButton = (AbstractButton)event.getSource();
                //Default Style Button
                if(theButton == defaultStyleJB){
                    System.out.println("Default Style Button Clicked!");
                //Change Background Button
                if(theButton == changeBackgroundJB){
                    System.out.println("Change Background Button Clicked!");
                    String backgroundURL = cssGenerator.getBackground();
                    if(backgroundURL != ""){
                        cssGenerator.setBackgroundChanged(true);
                        cssGenerator.setBackground(backgroundURL);
                        cssGenerator.outputCSSFile();
                        System.out.println("Backgroudn Changed, CSS File Written");
                    else{
                        System.out.println("No Background Selected");
         *Mouse Listener Inner Class*
        public class backgroundMouseListener implements MouseListener{
            public void mouseClicked(MouseEvent e){
                //get component
                JPanel tempBackgroundJP = new JPanel();
                tempBackgroundJP = (JPanel)e.getComponent();
                System.out.println("Background Panel Clicked");
                //change component colour
                if(selectedComponent == null){
                    selectedComponent = tempBackgroundJP;
                else{
                    changeColour((JPanel)selectedComponent, false);
                    selectedComponent = tempBackgroundJP;
                changeColour((JPanel)selectedComponent, true);
                //set background URL
                cssGenerator.setBackground(tempBackgroundJP.getName());
            public void mousePressed(MouseEvent e){
            public void mouseReleased(MouseEvent e){
            public void mouseEntered(MouseEvent e){
            public void mouseExited(MouseEvent e){
    }JApplet Class, this is what I plugged the GUI into after I made the change from Application to JApplet.
    public class AppletTest extends JApplet{
        public void init() { 
            System.out.println("Creating GUI");
            AppletGUI theGUI = new AppletGUI();
            theGUI.setVisible(true);
            Container content = getContentPane();
            content.setBackground(Color.white);
            content.setLayout(new FlowLayout());
            content.add(theGUI);
            AppletGUI theGUI = new AppletGUI();
            theGUI.setVisible(true);
            setContentPane(theGUI);
            System.out.println("GUI Displayed");
        public static void main(String[] args){
            AppletTest at = new AppletTest();
            at.init();
            at.start();
    }The CSS Generator Class. This exists because once I have the basic program working I intend to expand upon it and add multiple tabs to the GUI, each one allowing the user to change different style options. Each style option to be changed will be changed wit ha different method in this class.
    public class CSSGenerator {
        //Variables
        String background = "";
        ArrayList<String> backgroundCSS;
        //Flags
        boolean backgroundChanged = false;
        //Sets and Gets
        //For Variables
        public void setBackground(String theBackground){
            background = theBackground;
        public String getBackground(){
            return background;
        //For Flags
        public void setBackgroundChanged(boolean isBackgroundChanged){
            backgroundChanged = isBackgroundChanged;
        public boolean getBackgroundChanged(){
            return backgroundChanged;
        //background generator
        public ArrayList<String> backgroundGenerator(String backgroundURL){
            //get the URL for the background
            backgroundURL = background;
            //creat a new array list of strings
            ArrayList<String> backgroundCSS = new ArrayList<String>();
            //add the strings for the background options to the array list
            backgroundCSS.add("body");
            backgroundCSS.add("{");
            backgroundCSS.add("background-image: url(" + backgroundURL + ");");
            backgroundCSS.add("background-color: #ff0000");
            backgroundCSS.add("}");
            return backgroundCSS;
        //Write CSS to File
        public void outputCSSFile(){
            try{
                //Create CSS file
                System.out.print("creating file");
                FileWriter cssWriter = new FileWriter("C:/Documents and Settings/Gwilym/My Documents/Applet Data/CustomStyle.css");
                System.out.print("file created");
                System.out.print("creating buffered writer");
                BufferedWriter out = new BufferedWriter(cssWriter);
                System.out.print("buffered writer created");
                //check which settings have been changed
                //check background flag
                if(getBackgroundChanged() == true){
                    System.out.print("retrieving arraylist");
                    ArrayList<String> tempBGOptions = backgroundGenerator(getBackground());
                    System.out.print("arraylist retrieved");
                    int j = tempBGOptions.size();
                    for(int i = 0; i < j ; i++){
                        System.out.print("writing to the file");
                        out.write(tempBGOptions.get(i));
                        out.newLine();
                        System.out.print("written to the file");
                out.close();
            }catch (Exception e){//Catch exception if any
                System.out.println("Error: Failed to write CSS file");
        /** Creates a new instance of CSSGenerator */
        public CSSGenerator() {
    }The Backgrounds Class. This class exists because I didnt want there to just be a hardcoded lsit of backgrounds, I wanted it to be possible to add new ones to the list without simply lettign users upload their own images (since the intended users are kids and this sharepoint site is used for educational purposes, I dont want them uplaoded inapropraite backgrounds) but I do want the site admin to be able to add more images to the list. for this reason the backgrounds are taken from a list in a text file that will be stored in the same location as the applet, the file specifies the background name, where it is stored, and where a thumbnail image is stored.
    public class Backgrounds {
        //Array Lists
        private ArrayList<JPanel> backgroundsList;
        private ArrayList<String> backgroundsData;
        //Set And Get Methods
        public ArrayList getBackgroundsList(){
            return backgroundsList;
        //ArrayList Population Methods
        public void populateBackgroundsData(){
            //decalre the input streams and create a new fiel hat points to the BackgroundsData file
            File backgroundsDataFile = new File("C:/Documents and Settings/Gwilym/My Documents/Applet Data/BackgroundsData.txt");
            FileInputStream backgroundsFIS = null;
            BufferedInputStream backgroundsBIS = null;
            DataInputStream backgroundsDIS = null;
            try {
                backgroundsFIS = new FileInputStream(backgroundsDataFile);
                backgroundsBIS = new BufferedInputStream(backgroundsFIS);
                backgroundsDIS = new DataInputStream(backgroundsBIS);
                backgroundsData = new ArrayList<String>();
                String inputtedData = null;
                //loops until it reaches the end of the file
                while (backgroundsDIS.available() != 0) {
                    //reads in the data to be stored in an array list
                    inputtedData = backgroundsDIS.readLine();
                    backgroundsData.add(inputtedData);
            //TESTING
            System.out.println("\n\nTESTING: populateBackgroundsData()");
            int j = backgroundsData.size();
            for(int i = 0; i < j; i++){
                System.out.println("Index " + i + " = " + backgroundsData.get(i));
            System.out.println("\n\n");
            //close all stremas
            backgroundsFIS.close();
            backgroundsBIS.close();
            backgroundsDIS.close();
            } catch (FileNotFoundException e) {
                System.out.println("Error: File Not Found");
            } catch (IOException e) {
                System.out.println("Error: IO Exception Thrown");
        public void populateBackgroundsList(){
            backgroundsList = new ArrayList<JPanel>();
            int j = backgroundsData.size();
            System.out.println("number of backgrounds = " + j);
            backgroundsList = new ArrayList<JPanel>();
            for(int i = 0; i < j; i++){
                String tempBackgroundData = backgroundsData.get(i);
                JPanel backgroundJP = new JPanel(new GridLayout(1,2));
                JLabel backgroundNameJL = new JLabel();               
                JLabel backgroundIconJL = new JLabel();
                //split the string string and egt the background name and URL
                String[] splitBGData = tempBackgroundData.split(",");
                String backgroundName = splitBGData[0];
                String backgroundURL = splitBGData[1];
                String backgroundIcon = splitBGData[2];
                System.out.println("\nbackgroundName = " + backgroundName);
                System.out.println("\nbackgroundURL = " + backgroundURL);
                System.out.println("\nbackgroundIcon = " + backgroundIcon + "\n");
                backgroundNameJL.setText(backgroundName);
                backgroundIconJL.setIcon(new javax.swing.ImageIcon(backgroundIcon));
                backgroundJP.add(backgroundNameJL);
                backgroundJP.add(backgroundIconJL);
                backgroundJP.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
                //Name the JP as the background URL so it can be found
                //May be useful sicne the data file may need to contain 3 fields in future
                //this is incase the preview image (icon) is different from the acctual background
                //most liekly in the case of more complex ppictures rather then repeating patterns
                backgroundJP.setName(backgroundURL);
                //Add the JP to the Array List
                backgroundsList.add(backgroundJP);
            //TESTING
            System.out.println("\n\nTESTING: populateBackgroundsList()");
            j = backgroundsList.size();
            for(int i = 0; i < j; i++){
                System.out.println("Index " + i + " = " + backgroundsList.get(i));
            System.out.println("\n\n");
    }So thats my program so far, if theres anythign that needs clarifying then please jsut ask. Thank you very much for the help!

  • "Error writing to file" when installing Oracle9i

    I am fairly new to Oracle and have not been able to install Oracle 9i on my Redhat 7.2 box. In three attempts to install I have encountered the same error at some point, usually early on 5% or 10% into the install.
    The error is:
         "Error in writing to file /usr/oracle/product/9.2.0/olap/wrksht/wks.jar"
    However, it has not happened on the same file each time. I have stopped the installation of that component, but it encounters the same error on other files. I have tried redownloading the oracle disks and reinstalling, but to no avail. I read on one posting that Oracle needs to have glib2.2(rather than glib1.2) installed, so I downloaded it and will be trying that later today. If anyone has encountered this error and knows how to solve it I would appreciate the help. Below I have listed my computer configuration and I have attached the portion of the install log that identifies the error that takes place.
         Thanks
         Ed
         Here is my setup:
         Dual boot system running Redhat 7.2 and Win2k      server.
         Pentium III 400 MHZ
         256 MB of RAM
         30 GB Hard drive split in half-- 15GB for linux      15GB for windows.
         The mount points for linux are
         /          400 MB
         /boot      400 MB
         /home          1GB
         /tmp          600 MB
         /swap          600 MB
         /usr          12GB
         ORACLE_HOME is /usr/oracle/product/9.2.0
         all data files and software are under /usr/oracle
         Portion of the install log:
    Starting install install phase 1 of component Oracle OLAP Worksheet
    Calling query areasQueries2.2.0.7.0 getProductHome
    name = oracle.swd.jre
    startVersion = 1.1.8.0.0
    endVersion = 1.1.8.99.99
    acceptCompatible = null
    Query returned : /usr/oracle/jre/1.1.8
    Setting value of JDK_ROOT to /usr/oracle/jre/1.1.8
    Calling action fileActions2.2.0.10.0 copyGroupFromJar
         selectedNodes = null
         copyGroup = worksheet
         permissions = 644
         owner = null
         group = null
         copyAsText = null
         JarLoc = /tmp/OraInstall2003-01-23_03-02-09PM/temp57
         gpEntries = [[xsjwork.jar ->%ORACLE_HOME%/olap/wrksht/xsjwork.jar 1803268 plats=1=>
    Exception thrown from action: copyGroupFromJar
    Exception Name: IOException2
    Exception String: Error in writing to file /usr/oracle/product/9.2.0/olap/wrksht/wks.jar
    Exception Severity: 2
    *** Cancel Dialog:  ***
    User selected: Stop installation of all products.
    Exception handling set to prompt user with options to  RETRY  IGNORE
    User choice : User selected stop installation of all components
    Error in writing to file /usr/oracle/product/9.2.0/olap/wrksht/wks.jar
    Unable to read the list of homes from the inventory.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi,
    Did you guys finally find solution to the problem?
    I have been trying to install Oracle 9.2.0.1 on redhat 8.0 box, for ages now. I get the following error first during install
    Error in writing to file libclntsh.so.9.0
    Then it is a series of errors, similar.
    In the end there is the dreaded linking error... for the ins_rdbms.mk sdo_on
    i just cant handle it.
    What the hell is wrong?
    I have done everything right as far as i know... any solutions?
    cheers

  • Problem writing to file

    I'm working on a program that asks for the users name. after that its supposed to pull the current date and time and print that into a file along with the users name.
    my problem is when i open the .txt file i get several characters i dont recogize and then my name at the end.
    Thanks for the help:
    public class CIS314Exam1MarkWellsFrame
    private ObjectOutputStream output;
    public void openFile()
    try
    output = new ObjectOutputStream(new FileOutputStream("guestlog.txt"));
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "You do not have access to this file");
    System.exit(1);
    public void insertName()
    try
    Date today = new Date();
    //utput.writeObject(today);
    //String name = JOptionPane.showInputDialog("Enter Name");
    String name = "Mark";
    output.writeObject(name);
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "Error writing to file");
    return;
    public void closeFile()
    try
    if(output !=null)
    output.close();
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "Error Closing File");
    System.exit(1);
    System.exit(0);
    }

    This isnt the correct forum for this question. Use tags when posting code.  Post the contents of the .txt file and what unexpected characters you are getting.                                                                                                                                                                                                                                                                                                                                           

  • Error writing to file during iTunes 10.6 installation - Help!!

    I am trying to update iTunes to 10.6 but I get 'Error writing to file C:\Config.Msi\1b0f1d.rbf. Verify that you have access to that directory' I am presented with the option to 'Retry' or 'Cancel' after choosing retry on multiple occassions the update will not complete. I have a new pc on Windows 7 Home Premium 64-bit system. I have never had this problem before. Thanks in advance.

    Wierdly after persistance it has worked :s not sure how. but I have iTunes 10.6 which is the main thing!

  • Not writing to file

    Hi,
    I have made a program that reads a string, converts it to bytes, then writes to a file.
    Well i got the first two working, but its not writing to file. I know it should work cos i have written to file on my previous tests, but when i used a FOR loop it stoped working. Do ya know why. Below is the code...
    for (int a = 0;a = bytes.length - 1;a++){
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);
    My friend told me to use bytes.length - 1 as it is meant to stop the OUTOFBOUNDS error.
    OK,
    my regards
    Below is the whole program, its a bit messy cos i got lots of old code that i have blocked.
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.String;
    public class sender implements Runnable {
    int i= 0;
    String mes;
    int count =0;
    int b = 0;
    boolean yes = false;
    public static void main (String[] arguments) {
    Thread th = new Thread (new sender());
    th.start ();
    //sender();
    //while (true){}
    public void run() {
    try {
    Thread.sleep(100);
    } catch (InterruptedException e) {}
    String mesdialog = JOptionPane.showInputDialog(null,
    "Enter your message");
    mes = mesdialog.toString();
    try {
    //FileOutputStream of = new
    //FileOutputStream ("send.txt");
    FileWriter of = new
    FileWriter("send.txt");
    //BufferedReader in = new
    // BufferedReader(fr);
    //while (true){}
    int i = 66;
    boolean eof = false;
    int inChar = 0;
    //String inChar;
    byte[] bytes = mes.getBytes();
    /* < disable / enable
    do {
    int n=Integer.MIN_VALUE;
    try{
    n = Integer.parseInt(mes);
    } catch (NumberFormatException nfe){
    //inChar = n;
    if (inChar != -1) {
    byte outChar = (byte)inChar* ;
    //char outChar = (char)inChar ;
    of.write(outChar);
    System.out.println("" + outChar);
    //of.write(mes,0,20);
    } else
    eof = true;
    } while (!eof);//*/
    for (int a = 0;a = bytes.length - 1;a++){
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);
    while (!yes) {
    if (bytes[b] == 32 )
    yes = true;
    else {
    of.write(bytes);
    System.out.print(" " + bytes[b]);
    b++;
    //System.exit(0);
    //outfile.write(input);
    } catch (IOException e) {
    System.out.print("AAA ERROR");}

    your friend was obviously wrong.
    for (int a = 0;a = bytes.length - 1;a++){ // that does nothing
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);
    }the above "for" loop says :
    1:initialize a with 0;
    2:do loop while a=bytes.length(<-that's completely wrong. it should be
    a boolean expression);
    3:for each loop increment "a" by one.
    try this:for (int a = 0;a < bytes.length;a++){
    of.write(bytes[a]);
    System.out.print(" " + bytes[a] + " : " + bytes.length);

  • Writing to file

    public static void main(String args[]) throws Exception
    String str1;
    int length;
    BufferedReader inpu=new BufferedReader(new InputStreamReader(System.in));;
    System.out.println("Enter something: ");
    str1=inpu.readLine();
    System.out.println("hai"+" "+str1);
    i ve used the above code to read an input from the user now i want to write this to a file.plz tell me how to do it

    ya i tried using FileWriter
    But is there any other methods
    import java.io.*;
    class readtofile
    public static void main(String args[]) throws Exception
    String str1;
    int length;
    //stream given to inputstream reader then buffered usin buffered reader
    BufferedReader inpu=new BufferedReader(new InputStreamReader(System.in));;
    System.out.println("Enter something: ");
    str1=inpu.readLine();
    System.out.println("hai"+" "+str1);
    //opening a new file for output
    File outfile_1= new File("testout.txt");
    //using filewriter class for writing to file
    FileWriter out= new FileWriter(outfile_1);
    out.write(str1);
    out.close();
    }

  • Writing to file in JUnit test case? Not working?

    I have a singleton class called InstantLogger that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?
    Thanks,

    avalanche333 wrote:
    I have a singleton class called InstantLogger Ouch.
    that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.Oh, brother.
    >
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?Um, no.
    Your code is wrong. You're assuming something that isn't correct. You're also making the assumption that just because it "works" in another context that it's right in all contexts. The two aren't the same, be it configuration or something else.
    Singleton? That GoF pattern has been voted off the island. Didn't you hear?
    http://code.google.com/p/google-singleton-detector/
    %

  • Writing to file with ObjectOutputStream

    ApartmentWriterProgram asks information about apartments
    and saves it to a file.
    For some reason it doesnt save information, it writes:
    Writing to file "+file+ " failed.
    So there happens IOException in the method write(Apartment apartment).
    Or in the run().
    I dont know what's wrong. Do you?
    public class ApartmentFileHandler extends Object implements Serializable {
        private OutputStream outStream;
        private ObjectOutputStream obStream;
        private String filePath;
            public ApartmentFileHandler(String filePath) {
               this.filePath = filePath;
    /** Writes the given apartment data in the file. If the file already
    exists, the old contents are overwritten.
    Parameters:
    apartment - the apartment to be written in the file
    Throws:
    IOException - if other problems arose when handling the file (e.g. the
    file could not be written)
            public void write(Apartment apartment)
               throws IOException {
               outStream = new FileOutputStream(filePath);
               obStream = new ObjectOutputStream(outStream);
               obStream.writeObject(apartment);
    import java.io.*;
    import java.util.*;
    public class ApartmentWriterProgram
    extends Object
        private KeyboardReader keyboardReader;
        private List roomsInList;
        private Room[] rooms;
        private int numberOfRooms;
        private String file;
              public ApartmentWriterProgram()
                this.keyboardReader = new KeyboardReader();
                this.roomsInList = new ArrayList();
                this.rooms = new Room [numberOfRooms];
    /** Runs the writer program. The program asks the user for some
    apartment data and a file name, and saves the data in the file. */
              public void run() {
                try {
                  numberOfRooms = keyboardReader.getInt("Give number of rooms: ");
                  for (int i =1; i<numberOfRooms+1; i++) {
                     String type =keyboardReader.getString("Give " +i+ ". " + "type of the room: ");
                     double area =keyboardReader.getDouble("Give " +i+ ". " + "area of room: ");
                     Room room= new Room(type, area);
                     this.roomsInList.add(huone);
                  roomsInList.toArray(rooms);
                  Apartment apartment = new Apartment(rooms);
                  System.out.println();
                  file = keyboardReader.getString("Give name of the file: ");
                  ApartmentFileHandler handler = new ApartmentFileHandler(file);
                  handler.write(apartment);
               } catch (IOException ioe) {
                 System.out.println("Writing to file "+file+ " failed.");
             public static void main(String[]  args) {
                  ApartmentWriterProgram program = new ApartmentWriterProgram();
                  program.run();
    }

    There is nothing to gain in not putting the throws IOException in the write method, since the exception object will have the information about the actual problem.
    Is this a typo for the this post?                 this.roomsInList.add(huone); should be room nes pas.
    What exception is actually thrown? To find out useSystem.out.println("Exception: " + ioe);Then wonder why you have the AppartmentFileHandler implement Serializable when you are not writing that object to the file.

Maybe you are looking for