Bit Flags VS Boolean Flags

Hi here are two code snippets:
One with boolean flags;
public class BooleanFlags {
     private boolean _flag1 = false;
     private boolean _flag2 = false;
     private boolean _flag3 = false;
     private boolean _flag4 = false;
     public boolean isFlag1() {
          return this._flag1;
     public void setFlag1(boolean flag1) {
          this._flag1 = flag1;
     public boolean isFlag2() {
          return this._flag2;
     public void setFlag2(boolean flag2) {
          this._flag2 = flag2;
     public boolean isFlag3() {
          return this._flag3;
     public void setFlag3(boolean flag3) {
          this._flag3 = flag3;
     public boolean isFlag4() {
          return this._flag4;
     public void setFlag4(boolean flag4) {
          this._flag4 = flag4;
}Another with bit flags
public class BitFlags {
     static final int _FLAG1 = 1;
     static final int _FLAG2 = 2;
     static final int _FLAG3 = 4;
     static final int _FLAG4 = 8;
     private int _flags = 0;
     public int getFlags() {
          return this._flags;
     public void setFlags(int flags) {
          this._flags = flags;
}Testing code
public class TestFlags {
     public static void main(String[] args) {
          // bit
          BitFlags t = new BitFlags();
          t.setFlags(t.getFlags() | BitFlags._FLAG1);
          t.setFlags(t.getFlags() | BitFlags._FLAG2);
          if ((t.getFlags() & BitFlags._FLAG2) == BitFlags._FLAG2) {
               System.out.println("FLAG2");
          //boolean
          BooleanFlags bf = new BooleanFlags();
          bf.setFlag1(true);
          bf.setFlag2(true);
          if ( bf.isFlag2() ) {
               System.out.println("FLAG2");
}I counted the number bytes used by each classes.
Each character of a class name weighs 3 bytes each.
For a default package BitFlags.class file weighs
for 1 flag 519 bytes
for 2 flags 549 bytes
for 3 flags 579 bytes
for 4 flags 609 bytes
So that's 30 bytes per flags.
BooleanFlags.class file weighs
for 1 flag 484 bytes
for 2 flag 686 bytes
for 3 flags 888 bytes
for 4 flags 1090 bytes
So that's 202 bytes per flags.
I don't know though how the size of the class file is correlated with the memory used at run time. Apparently boolean flags suck.
But wait.
A) Which one is the most efficient memory wise at run time?
Degrees of freedom:
-the number of flags used,
-the number of instances that will be created.
An important question needs to be answered, that is whether a boolean literal weighs indeed a 1 bit of memory or more. I don't know.
When reasoning from a conceptual point of view, the memory usage for bit flags will take 4 bytes per instance for the _flags field and a constant 4 bytes per static flag definition,
N > 0, X > 0
32 * N + X*32 = A bits
Boolean flags take 1 bit per instance per flag
1 * N * X = B bits
So if we want A > B
32N >(N-32) X
If N > 32 then 32N/(N-32) > X
If N = 32 then INF>X
If N < 32 then 32N/(N-32) < X
To have A > B we need
N = 1 : 0 < X < INF
N = 31 : 0 < X < INF
N = 32 : 0< X < INF
N = 33 : 0 < X < 1056
N = 40 : 0 < X < 160
N = 50 : 0 < X < 89
N = 100 : 0 < X < 48
N = 10000 : 0 < X < 33
As you can guess, as N goes to infinite, X goes to 32.
For a very large number of instances, boolean flags will take less memory than bit flags if you have less than 32 flags (dual will take more memory if have more than 32 flags) Boolean flags always beat bit flags for less than 33 instances
Now I don't know what really happens in practice. Because one should take heed of the way classes are managed. The code for getting boolean flags takes a lot of room. Now if that code is loaded once. That's ok. But if the get and set methods for every bit flags are loaded for every instance. Then that's bad.
A solution to this would be to use public members and remove getters and setters.
The most important issue though is how boolean literal are managed by the memory.
From a purely aesthetic perspective, the usage of boolean flag is nicer. Testing the value of a bit flag is ugly.
Cheers

The hardware level is irrelevent. If the best you can
do is "look for multiple boolean variables in the same
class and pack them into a single byte," why can't
this be done by JVM writers for you?
Although tecnically possible, I suspect only that someone who didn't know what they were doing would implement it that way.
First keep in mind that this is something the VM must do. The compiler has nothing to do with. And it does mean that just for the VM to access values (not via java) that the code will be slower. It is because of this that C/C++ language allows developers to decide whether to pack integer numerics or not.
Second consider the following...
    void myMethod()
       boolean b = true;
          boolean b1_1 = true;
          String s1 = "test";
          boolean b1_2 = true;
          String s2 = "test";
          boolean b2_1 = true;
          boolean b2_1 = true;
    }Now the compiler is going to render the above by using stack frame references as
#1 = b
#2 = b1_1 and s2
#3 = s1 and b2_1
#4 = b1_2 and b2_1
So now the VM is going to have to know that #1 holds all the bits and sometimes those bits are used by #2 and sometime not.
Now one could write code that would do that. But I would be a lot slower and I suspect it would actually take more space due to maintenance information information needed to handle it all.
And the result would be that all Java apps would be slower and only a few (definitely less than 1%) would save any space. I don't think a reasonable VM vendor would take that path.

Similar Messages

  • SetOpaque(boolean flag);

    Hello:
    I have got your code on how to set a background image. Thank you so much.
    But I have another question , my question is that
    what is the purpose of the following method
    setOpaque(boolean flag);
    and also this method belongs to which class?

    If a component has opaque flag set then it is expected to paint every pixel in its bounds (potentially increasing efficiency, for example any area of a component under this component need not paint those pixels).
    See:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html#setOpaque(boolean)
    Doh! Didn't see your other thread (which had already been answered). Please don't cross-post:
    http://forum.java.sun.com/thread.jspa?threadID=5223142&tstart=0
    Edited by: smithberry on Oct 5, 2007 9:29 AM

  • BADI to get GR done flag , Final Invoice flag and Delivery completed flag

    Hi all,
    An Idoc needs to be triggered for PO line items to indicate different flags. As soon  as MIGO or MIRO is done for PO line item, I have to check three flags namely GR done flag , Final Invoice flag and Delivery completed flag and send information of these flags as set.
    I want to know which BADI or User exit will give information  to indicate that either of one or all above flags are set for PO line item as soon as MIGO or MIRO is used.
    Thanks in advance,
    Madhura

    HI,
    When Purchase order is created with reference to contract, system carry
    out the check whether Document date of PO should be within contract
    "validity start" and "vaidity end" date. If document date is outside
    the "validity start" and "validity end" date of PO, message 06 040
    "Validity period of contract does not start until &" or message
    06 041 " Validity period of contract expired on &" is raised.
    Same check is also carried out during any change in PO (txn ME22N).
    Please use one of following option to close the PO.
    1. Change the category of message 06041 as warning in customization.
    Txn OLME.
    Environment Data -> Define Attributes of System Messages ->System
    Messages
    2. Change the validity end date in contract and close the Purchase order. Validity end date can be reverted.
    BR
    Nadia Orlandi

  • Un-flagged Email in Flagged List

    I have email in Mail that was flagged and the flag subsequently removed but the emails remain in the Flagged list without a Flag!? Emails before, and since, I flag and then un-flag behave correctly and dissapear from the list.
    How can I get these emails to not be in the Flagged list?
    Peter R Hawkes

    Just reported it as a bug. Let's see what happens.
    I'm pretty sure this used to work on iOS 6.. but it's not working under iOS 7, making flagged messages pretty useless.
    It does, however, work just fine on MacOS X's Mail.app, so there's some inconsistency about what Flagged messages means here. Makes me think it's just something they missed in iOS 7 and it will be back..
    ..or they'll pull the functionality out of MacOS. :-)
    \marc

  • How to populate a static junk dimension made of N boolean flags

    Hi, we want to populate a junk dimension (a table with N boolean fields - 18 in our case).
    The records must contain all the possibile combinations of all the fields (with 18 integer fields whose value can be either 0 or 1, the number of possible combinations is 262144).
    I'm looking for suggestions on how to do this (with a single SQL statement or with a cursor inside a procedure, they are both fine).
    Thanks,
    Andrea

    You could use cross products/joins to achieve the result. Here is an example:
    SQL> WITH boolean_flags AS
      2  (
      3          SELECT  0 AS FLG FROM DUAL UNION ALL
      4          SELECT  1 AS FLG FROM DUAL
      5  )
      6  SELECT  A.FLG
      7  ,       B.FLG
      8  ,       C.FLG
      9  FROM    BOOLEAN_FLAGS   A
    10  ,       BOOLEAN_FLAGS   B
    11  ,       BOOLEAN_FLAGS   C
    12  /
           FLG        FLG        FLG
             0          0          0
             0          0          1
             0          1          0
             0          1          1
             1          0          0
             1          0          1
             1          1          0
             1          1          1If you need it to be more dynamic you can generate the SQL dynamically as shown below. This example would work for the number of columns ranging from 1-26 (I didn't do heavy testing):
    SQL> VAR c REFCURSOR;
    SQL>
    SQL> DECLARE
      2          numDimensions   NUMBER  := 3;
      3          sqlText         VARCHAR2(4000) :='WITH boolean_flags AS
      4                                          (
      5                                                  SELECT  0 AS FLG FROM DUAL UNION ALL
      6                                                  SELECT  1 AS FLG FROM DUAL
      7                                          )
      8                                          SELECT A.FLG ';
      9          sqlFromText     VARCHAR2(4000) :='FROM BOOLEAN_FLAGS    A';
    10  BEGIN
    11          FOR i IN 2..numDimensions
    12          LOOP
    13                  sqlText := sqlText || ', ' || CHR(64+i) || '.FLG ';
    14
    15                  sqlFromText := sqlFromText || ', BOOLEAN_FLAGS ' || CHR(64+i);
    16          END LOOP;
    17
    18          OPEN :c FOR sqlText || sqlFromText;
    19  END;
    20  /
    PL/SQL procedure successfully completed.
    SQL> PRINT C
           FLG        FLG        FLG
             0          0          0
             0          0          1
             0          1          0
             0          1          1
             1          0          0
             1          0          1
             1          1          0
             1          1          1
    8 rows selected.Edited by: Centinul on Dec 28, 2009 9:35 AM

  • Green flag to Red flag in SXMB_MONI

    Hello experts,
    During the FILE -> BPM -> RFC scenario, i use a mapping step to intentionally throw an exception to make application errors visible in the monitoring logs (SXMB_MONI).
    This way a red flag on the outbound status field is shown if the condition to execute this mapping is met.
    This works well for its intended purpose in a scenario, but doing the same approach for another scenario (everything is done exactly the same way), the second scenario shows a green flag on the outbound status field.
    the Greed flag dictates "message is scheduled on the outbound side", once i click the "PE", i can see the queue has failed in the BPM.
    I am not clear as to why it displays green flag instead of a red flag. The requirement is to display the red flag. (and so that no queue-clearing is required).
    Any ideas on how to achieve this is greatly appreciated.
    Thanks.

    hi, thanks,
    when i click to the Queue ID, it opens the SMQ2 (qRFC inbound) .. here i can only see 1 LUW displayed, with SYSFAIL status. This is because of the intentional exception thrown via a mapping step.
    Instead of failing at the queue (and get a green flag in sxmb_moni), it should show error status in sxmb_moni with red flag in the "outbound status" field.
    If i clear this and unlock the queue, the next execution again falls into a failure in queue status (and a green flag in the sxmb_moni).
    I appreciate any other ideas.
    Thank you.

  • Under Mail Flagged shows 1 "flagged" Nothing there when I click on it and will not remove the number1 even when I mark as read...

    In Mail under Mailboxes > Flagged shows 1. There is nothing there. Have tried to mark as read and 1 still remains. How do I get rid of it?

    I have tried the holding down the icon to get the shaking apps and although the X shows up clicking on it does nothing.
    Mountain Lion is not for IOS based devices.
    It's the Mac OS X operating system for Macintosh computers.

  • TCP Flags and FW flags

                       Hi everyone,
    I was reading cisco documentation
    http://www.cisco.com/en/US/products/ps6120/products_tech_note09186a0080bcad00.shtml
    It says for outbound connection from FW
    TCP FLAG                            FW FLAG
    SYN   --------------->                  saA
    SYN+ACK <-----------------          A
    ACK    ------------------>                U
    Need to understand that TCP FLAGS are sent by PC  from inside the Network to the FW.
    FW Flags are generated  by FW  ? or FW flags are sent by server  from  outside to the FW?
    Thanks
    Mahesh

    Hi Mahesh,
    The TCP flags you mention above refer to the 3 Way Handshake between a host opening a TCP connection to a server.
    The flags on the ASA firewall are shown with commands "show conn" or "show conn detail" which show what the state of the TCP connection is from the ASAs perspective.
    You can use the "show conn detail" to view the different flags and their meaning on the ASA CLI.
    As you could see referring to the "show conn detail" output the FW Flags would mean this
    saA = ASA has seen the "inside" host send a TCP SYN. It is still waiting for the "outside" host to send a TCP SYN and TCP ACK. It is also waiting for a TCP ACK from the "inside" host
    A = As the ASA receives the TCP SYN, ACK from the "outside" host, it removes all but the flag that represents that its waiting the ACK from the "inside" host
    U = When it receives the TCP ACK from the "inside" host it will finally show the flag U which means the TCP connection is up
    UIO = When Data starts passing through this TCP connection the ASA will also add the flags I and O. These means Data in Inbound and Outbound direction.
    The terms "inside" and "outside" above DONT refer to the "nameif" of an interface. They refer to the interface "security-level". The one with higher "security-level" is refered to in the ASA flags by inside and the one with lower "security-level" is referred to as the outside.
    Here is also a good page online about the same subject
    http://ccnpsecurity.blogspot.fi/2011/11/asa-flags-associated-with-tcp.html
    Hope this helps
    - Jouni

  • How do i remove type form a flag and the flag return to original?

    help on removing a text from a flag and flag returning to original?

    Gary,
    IT sounds as if you have a number of rectangles/squares forming the checkered pattern of the flag.
    If the pattern is repetitive, you may be able to Alt/OptionClick some of those round the gap and move copies to fill it; rectangles/squares with cutouts would have to be deleted.
    A screenshot may give rise to better suggestions.
    It is an hour and a half past midnight over here, so I shall have to attend to other duties, before the sun is up.

  • Can't find flagged emails in flag folder even when it indicates I have 11?This is on iPhone 5 - IOS 7

    Haven't found an answer although I've seen others asking same question. This should be addressed directly in Apple Support.
    Is help on the way?

    Hi Pete. I installed IOS7.1.1 last week and the video/camera app has frozen !I get a blurred picture and cannot take any photos or vids. I went to the Genius Bar in uk and they couldn't help!The phone is out of warrenty! They said sell it on to them!  Not very good customer service!! It seems that IOS has a few problems.They rebooted phone but still no camera!Any ideas on how to fix it?;

  • How to wait for a variable to be set?

    Hi,
    I need to wait for a variable to be set. I tried this, but it didn't work (IllegalMonitorStateException). How to do it?
    Thanks!
    public class MyClass {
      private Boolean succed = null;
      public static boolean doStuff() {
        MyClass my = new MyClass();
        while (my.succed == null) {
          try {
            my.wait();
          } catch (InterruptedException e) { } // Nothing
        return my.succed.booleanValue();
      // and elsewhere set succed to Boolean.TRUE / FALSE and call notifyAll()
    }

    Try this:
    import java.util.*;
    public class Test {
      private Boolean  flag = null;
      public synchronized boolean waitForFlag() {
        boolean  res;
        while(flag == null) {
          try  { wait(); }  catch(InterruptedException e)  {}
        res  = flag.booleanValue();
        flag = null;
        notifyAll();
        return  res;
      public synchronized void setFlag(boolean  flag) {
        while(this.flag != null) {
          try  { wait(); }  catch(InterruptedException e)  {}
        this.flag = new Boolean(flag);
        notifyAll();
      public static void main(String[] args) {
        final Test  t = new Test();
        new Thread() {
          public void run() {
            System.out.println("1: " + t.waitForFlag());
        }.start();
        new Thread() {
          public void run() {
            System.out.println("2: " + t.waitForFlag());
        }.start();
        try  { Thread.sleep(5000); }  catch(InterruptedException e)  {}
        t.setFlag(true);
        t.setFlag(false);
    }

  • Why is the answer of the program such??

    I have a program code below.
    class Flag
    private boolean flag;
    public Flag() {
    boolean flag = true;
    public boolean getFlag() {
    return flag;
    public static void main(String[] args) {
    Flag f = new Flag();
    System.out.println(f.getFlag());
    When i run the program the output is false. I don't understand why? can anyone explain to me? Thanks

    I have a program code below.
    class Flag
    private boolean flag;
    public Flag() {
    boolean flag = true;
    public boolean getFlag() {
    return flag;
    public static void main(String[] args) {
    Flag f = new Flag();
    System.out.println(f.getFlag());
    When i run the program the output is false. I don't
    understand why? can anyone explain to me? ThanksThe correct one is:
    class Flag
       private boolean flag;
       public Flag()
          //this mean you change the flag variable in this method
          //boolean flag = true;   
          flag = true;
       public boolean getFlag()
          return flag;
       public static void main(String[] args)
          Flag f = new Flag();
          System.out.println(f.getFlag());

  • Managing bit flags in an array of bytes

    In my program, I have a large array of bytes. Some arbitrarily long groups of bytes in this array act as groups of bit flags. I need to be able to retrieve and manipulate these bit flags. I read that the best way to do this is with bitwise operations; something I have never learned before. I wrote methods that seem to work, but because I have never done anything like this before, can someone check my work?
    Here is an example program, where the only contents of the byte array is a single two-byte grouping of 16 bit flags:
    public class test
        static byte[] bytes = new byte[2];
        static byte[] pow2 = {1, 2, 4, 8, 16, 32, 64, -128};
        static byte[] pow2i = {-2, -3, -5, -9, -17, -33, -65, 127};
        public static void main(String[] args) throws Exception
            writeBitFlag(0, 6, true);
            for (int i = 0; i < 16; i++)   
                System.out.println("Flag " + i + ": " + getBitFlag(0, i));
            System.out.println();
            writeBitFlag(0, 12, true);
            invertBitFlag(0, 0);
            invertBitFlag(0, 0); 
            invertBitFlag(0, 1);
            for (int i = 0; i < 16; i++)   
                System.out.println("Flag " + i + ": " + getBitFlag(0, i));  
        }//end main
        public static boolean getBitFlag(int startAddress, int flag)
            return (bytes[startAddress + flag / 8] & pow2[flag %= 8]) == pow2[flag];
        }//end getBitFlag
        public static void invertBitFlag(int startAddress, int flag)
            bytes[startAddress + flag / 8] ^= pow2[flag % 8];
        }//end invertBitFlag
        public static void writeBitFlag(int startAddress, int flag, boolean flagVal)
            if (flagVal)
                bytes[startAddress + flag / 8] |= pow2[flag % 8];
            else
                bytes[startAddress + flag / 8] &= pow2i[flag % 8];
        }//end writeBitFlag      
    }//end class testDoes this look like the right way to do what I am trying to do?

    You could try BitSet which provides these function for you.
    public class test { 
        public static void main(String[] args) throws Exception {   
            byte[] bytes = new byte[2];
            writeBitFlag(bytes, 6, true);
            for (int i = 0; i < bytes.length*8; i++)   
                System.out.println("Flag " + i + ": " + getBitFlag(bytes, i));
            System.out.println();
            writeBitFlag(bytes, 12, true);
            invertBitFlag(bytes, 0);
            invertBitFlag(bytes, 0); 
            invertBitFlag(bytes, 1);
            for (int i = 0; i < bytes.length*8; i++)   
                System.out.println("Flag " + i + ": " + getBitFlag(bytes, i));  
        }//end main
        public static boolean getBitFlag(byte[] bytes, int flag) {
            return ((bytes[flag >> 3] >> flag) & 1) != 0;
        public static void invertBitFlag(byte[] bytes, int flag) {
            bytes[flag >> 3] ^= (1 << (flag & 7));
        public static void writeBitFlag(byte[] bytes, int flag, boolean flagVal) {
            if (flagVal)
                bytes[flag >> 3] |= (1 << (flag & 7));
            else
                bytes[flag >> 3] &= ~(1 << (flag & 7));
    }//end class test

  • Bit Shifting for Flags ( Constructive Criticism Please)

    I came up with a class that handles flag manipulation using Bitwise operators. Does anyone think this is more efficient than using boolean variables for flags? Or is this just overkill.
    The reason Im asking is Ive used this approach before on Muds that I have written/updated. Just wondering if it is outdated.
    * Allows for 64 different on/off flags.
    public class State
            public static final byte ST_00 = (byte)0 ;
            public static final byte ST_01 = (byte)1 ;
            ....fill here......
            public static final byte ST_63 = (byte)63 ;
         private int lowStates = 0;
         private int highStates = 0 ;
         public boolean is( byte bitIndex )
              if( bitIndex > 31 )     
                   return ( (highStates & ( 1 << (bitIndex%32) )) == 1 ? true :  false ) ;
              else
                   return ( (lowStates & ( 1 << bitIndex ) ) == 1 ? true : false ) ;
         public void remove( byte bitIndex )
              if( bitIndex > 31 )
                   highStates &= ~(1 << (bitIndex%32) ) ;
              else
                   lowStates &= ~(1 << bitIndex ) ;
         public void set( byte bitIndex )
              if( bitIndex > 31 )
                   highStates |= (1 << (bitIndex%32) ) ;
              else
                   lowStates |= (1 << bitIndex ) ;
         public void toggle( byte bitIndex )
              if( bitIndex > 31 )
                   highStates ^= (1 << (bitIndex%32) ) ;
              else
                   lowStates ^= (1 << bitIndex) ;
    * Simple implementation
    public class INeedFlags
           public static final byte FLAG_1 = ST_00 ;
           public static final byte FLAG_2 = ST_01 ;
           public State flags = new State() ;
           public static void main(String[] args)
                INeedFlags obj = new INeedFlags() ;
                obj.flags.set( FLAG_1 );
                obj.flags.toggle( FLAG_2 ) ;
                if( obj.flags.is( FLAG_1 ) )
                   System.out.println("Yep its set");
    }

    i often use bit flags.
    my variation is to have the flag constants as long bitmasks.
    this allows for multiple flag set / test in one instruction :
    if (flags.has(FLAG_1 | FLAG_3)) {..}
    also no bitshifting required should make it as fast as comparing booleans.
    ( in c++, the compiler optimises it away to almost nothing).
    the java code is a quick hack of your post (sorry about the indents)
    Adrian
      * Allows for 64 different on/off flags.
    public class State
        public static final long ST_00 = 0x00000001 ;
        public static final long ST_01 = 0x00000002 ;
        public static final long ST_02 = 0x00000004 ;
      ....fill here......
        public static final long ST_62 = 0x40000000 ;
        public static final long ST_63 = 0x80000000 ;
        public State(long bitFlags)
            state = bitFlags;
        private int state = 0;
        public long value()     
            return ( state );
        public boolean equals( long bitFlags )
            return ( state == bitFlags ) ;
        public boolean is( long bitFlag )
            return ( has(bitFlag) ) ;
        public boolean has( long bitFlags )
           return ( (state & bitFlags) != 0 ) ;
         public void clear( )
              state = 0 ;
         public void remove( long bitFlags )
              state &= ~bitFlags ;
         public void set( long bitFlags )
              state |= bitFlags ;
         public void toggle( long bitFlags )
              state ^= bitFlags ;
      * Simple implementation
    public class INeedFlags
            public static final long FLAG_1 = ST_00 ;
            public static final long FLAG_2 = ST_01 ;
            public static final long FLAG_3 = ST_02 ;
            public State flags = new State() ;
            public static void main(String[] args)
             * This still works
                 INeedFlags obj = new INeedFlags() ;
                 obj.flags.set( FLAG_1 );
                 obj.flags.toggle( FLAG_2 ) ;
                 if( obj.flags.is( FLAG_1 ) )
                    System.out.println("Yep its set");
               * but you can also say
                 obj.flags.clear( );
                 obj.flags.set(FLAG_1 | FLAG_2);
                 if( obj.flags.has( FLAG_2 | FLAG_3 ) )
                    System.out.println("one of them is set");

  • Is there a append flag in any of the PrintWriter methods--- urgent info pls

    hi,
    I have written a function writedata to output the result of a query to a file.I am calling this function from main.
    Its working fine if my output just single line.But the problem arises when i want output multiple line result.
    every time this method is called it overwrites the data written before.
    ie if the result of my query is two line
    My name is jack
    My name is Tom
    it is just displaying My name is Tom , overwriting the previously written data ie my name is jack.
    I dont know if i can set a boolean flag append here. I am not sure if using PrintWriter() i can do this.
    can anyone tell me if i can use any other class other than printwriter to output text to a file or is there a method using which i can append text to a file( ie in printwriter)
    thanks
    sagarika
    void writedata(String name,String loc,String len,String yr,String format,int price,String outfile) {
    try{  fileo = new File(outfile);
    fw = new FileWriter(fileo);
    pw = new PrintWriter(fw);
    pw.println("NAME " + name+" AT "+loc+" LENGTH "+len+" YEAR "+yr+" FORMAT "+format+" PRICE "+price);
    System.out.println("NAME " + name+" AT "+loc+" LENGTH "+len+" YEAR "+yr+" FORMAT "+format+" PRICE "+price);
    System.out.println(" inside writedata mtd");
    pw.close();
    } catch(IOException ex) {
    System.err.println("error is " + ex);
    } // void write data

    can anyone tell me if i can use any other class other
    than printwriter to output text to a file or is there
    a method using which i can append text to a file( ie
    in printwriter)
    This question would probably best be posted in one of the other forums such as the Java Programming forum.

Maybe you are looking for

  • How can I access deleted photos from my iPhoto Library Cache?

    My Macbook Pro broke about a year ago and I recently took the hard drive out to access the files. I have a hard drive enclosure to USB to my Acer (Windows) Laptop. I was looking through all the folders when I came across this: D:\Users\Lizee\Library\

  • Completely broken in Ubuntu: can't access profile

    I have a freshly installed Ubuntu 13.04 64bit. It came with Firefox 20 which was working fine, but was not the latest version. I ran "sudo apt-get install firefox" and it updated firefox to version 24. Now Firefox is broken and won't load. It systema

  • Poor qulaity video on iDVD

    I've made many DVDs after editing in IMovie but often get problems. The latest is the most annoying as I've transferred 6 movies, 2 slideshows and 2 trailers but the largest of these (a movie) doesn't play correctly. The dodgy one is 20 minutes long

  • Printing pictures thru the Web not clear whe nwe pick them up

    Our pictures look great in Iphoto but when we send them to the processor(Blacks or Ophoto) the pictures look like crap. Any thoughts on why?

  • Black window with white letters

    In the past several days a black window appears on the desktop with white writing saying restart your computer as there is a problem with the hard drive. I restart and the computer works just fine. I have a imac intel.