473,669 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

saved to file

20 New Member
hi
i have this code
but i have problem that is
i can ensert the NO of job and saved it on txt file named by memory
but when i close the file memory all data on this file is lost , how can i saved it without lost data
and i wont to make the file memory on the 100 kb
and when enter the total of the job great than 100 kb the program must be send for me message " i canot saved more than 100 kb "
help me



this code i upload it on this sit

http://www.2shared.com/file/2387324/...a/Fitting.html
Oct 16 '07 #1
21 1814
r035198x
13,262 MVP
hi
i have this code
but i have problem that is
i can ensert the NO of job and saved it on txt file named by memory
but when i close the file memory all data on this file is lost , how can i saved it without lost data
and i wont to make the file memory on the 100 kb
and when enter the total of the job great than 100 kb the program must be send for me message " i canot saved more than 100 kb "
help me



this code i upload it on this sit

http://www.2shared.com/file/2387324/a059371a/Fitting.html
You want us to help you and yet you post your code elsewhere?
Come on don't be lazy. It's just a matter of copy and paste. And use code tags when you post the code.
Oct 16 '07 #2
kamsmartx
20 New Member
hi
i have this code
but i have problem that is
i can ensert the NO of job and saved it on txt file named by memory
but when i close the file memory all data on this file is lost , how can i saved it without lost data
and i wont to make the file memory on the 100 kb
and when enter the total of the job great than 100 kb the program must be send for me message " i canot saved more than 100 kb "
help me


Expand|Select|Wrap|Line Numbers
  1.  
  2.    import java.awt.*;
  3.    import javax.swing.*;
  4.    import java.io.*;
  5.    import java.io.FileNotFoundException;     
  6.    import java.lang.SecurityException;
  7.    import java.util.*;       
  8.    import java.util.Formatter;               
  9.    import java.util.FormatterClosedException;
  10.    import java.util.NoSuchElementException;  
  11.    import java.util.Scanner;  
  12.  
  13. import java.io.InputStream;
  14. import java.io.OutputStream;
  15. import java.io.FileInputStream;
  16. import java.io.FileOutputStream;
  17. import java.io.FileReader;
  18. import java.io.FileNotFoundException;               
  19.  
  20.   public class FittingAllgorithm
  21.  {
  22.      private Formatter output; // object used to output text to file
  23.  
  24.      // enable user to open file
  25.      public void openFile()
  26.      {
  27.         try
  28.         {
  29.            output = new Formatter( "memory.txt" );
  30.         } // end try
  31.         catch ( SecurityException securityException )
  32.        {
  33.           System.err.println(
  34.               "You do not have write access to this file." );
  35.            System.exit( 1 );
  36.         } // end catch
  37.         catch ( FileNotFoundException filesNotFoundException )
  38.         {
  39.            System.err.println( "Error creating file." );
  40.            System.exit( 1 );
  41.         } // end catch
  42.      } // end method openFile
  43.  
  44.      // add records to file
  45.      public void addRecords()
  46.      {
  47.         // object to be written to file
  48.         Job record = new Job();
  49.  
  50.         Scanner input = new Scanner( System.in );
  51.  
  52.        System.out.printf( 
  53.        "%s\n%s\n%s\n%s\n%s\n","********************\n\nFitting Algorithem\n\n********************\n\nThis Create By\n",
  54.        "Khalid Ahmed Almallahy\n20032348\n\n********************\n",
  55.        "Supervesor by",
  56.        "\nMoamar Elyazgi.\n\n********************\n\n",
  57.        "Hint :- \n When You Wont to Exit Press <CTRL>+z\n\n========================================================\n\n" );
  58.  
  59.         System.out.printf( "%s\n%s\n",
  60.            "Enter First Jop 'Process' number must be greater than 0\n  Second Job 'Process'\n  Third Job 'Process'\n  last Job 'Process'",
  61.            "?" );
  62.  
  63.        while ( input.hasNext() ) // loop until end-of-file indicator
  64.         {
  65.            try // output values to file
  66.            {
  67.               // retrieve data to be output
  68.               record.setAccount ( input.nextInt() ); 
  69.               record.setaccount1( input.nextInt() );    
  70.               record.setaccount2( input.nextInt() );       
  71.               record.setaccount3( input.nextInt() );     
  72.  
  73.               if ( record.getAccount() > 0 )
  74.               {
  75.                  // write new record
  76.                  output.format( "%d %d %d %d \n", 
  77.                     record.getAccount(),
  78.                     record.getaccount1(),
  79.                     record.getaccount2(),       
  80.                     record.getaccount3() );                             
  81.               } // end if
  82.               else
  83.               {
  84.                  System.out.println(
  85.                     "Job number must be greater than 0." );
  86.               } // end else
  87.            } // end try
  88.            catch ( FormatterClosedException formatterClosedException )
  89.            {
  90.               System.err.println( "Error writing to file." );
  91.               return;
  92.            } // end catch
  93.            catch ( NoSuchElementException elementException )
  94.            {
  95.               System.err.println( "Invalid input. Please try again." );
  96.               input.nextLine(); // discard input so user can try again
  97.            } // end catch
  98.  
  99.           System.out.printf( "%s %s\n%s", "Enter account number greater than 0,",
  100.               "first Job, Second  Job and Third Job and so on.", "?\n" );
  101.         } // end while
  102.      } // end method addRecords
  103.      // close file
  104.     public void closeFile()
  105.      {
  106.         if ( output != null )
  107.            output.close();
  108.      } // end method closeFile
  109.  
  110.  
  111.      //////////////////////////////////////////////////////////////////////////
  112.  
  113.  
  114. int memory,dummycount;
  115. int process;
  116. int[] bestfit,worstfit,nextfit,firstfit;
  117.  
  118.      public void place()
  119.      {
  120.           Job record = new Job();
  121.  
  122.         Scanner inFile1= new Scanner(System.in);
  123.         Scanner iFile= new Scanner(System.in);
  124.  
  125.  
  126.  
  127. dummycount=0;
  128. while (inFile1.hasNext())
  129. {
  130. memory = inFile1.nextInt();
  131. dummycount=dummycount+1;
  132. firstfit =new int [dummycount];
  133.  
  134. inFile1.close();
  135.  
  136.  
  137. System.out.println("------For FirstFit algorithm---------");
  138.  
  139. inFile1= new Scanner(System.in);
  140.  
  141. dummycount=0;
  142. while (iFile.hasNext())
  143. {inFile1= new Scanner(System.in);
  144.  
  145. process = iFile.nextInt();
  146. while (inFile1.hasNext())
  147.  
  148. memory = inFile1.nextInt();
  149. if ((memory >=process)&&(dummycount< firstfit.length)&&(firstfit[dummycount]==0))
  150. {
  151. firstfit[dummycount]=process;
  152.  
  153.  
  154. System.out.println("memory partition" +" "+ memory +" will accomodate process that need"+ " " +process); 
  155. }
  156. }
  157.  
  158.  
  159. dummycount++;
  160. inFile1.close();
  161. }
  162.  
  163. iFile.close();
  164.  
  165.  
  166.  
  167. System.out.println("------For BestFit algorithm---------");
  168.  
  169.  
  170. nextfit =new int [dummycount];
  171.  
  172.  
  173.  
  174.  
  175. System.out.println("------For NextFit algorithm---------");
  176. dummycount=0;
  177. System.out.println("Got this far");
  178. iFile= new Scanner(System.in);
  179.  
  180. while (iFile.hasNext())
  181. {
  182.  
  183. process = iFile.nextInt();
  184. inFile1= new Scanner(System.in);
  185. while (inFile1.hasNext())
  186.  
  187. memory = inFile1.nextInt();
  188. if ((memory >=process)&&(dummycount< nextfit.length)&&(nextfit[dummycount]==0))
  189. {
  190. nextfit[dummycount]=process;
  191.  
  192. System.out.println("memory partition" +" "+ memory +" will accomodate process that need"+ " " +process); 
  193. }
  194. }
  195.  
  196.  
  197. dummycount++;
  198.  
  199. }
  200.  
  201. System.out.println("dummycount" +" "+dummycount);
  202. inFile1.close();
  203. iFile.close();
  204.  
  205. System.out.println("------For WorstFit algorithm---------");
  206.  
  207. return;
  208.  
  209.      }
  210.  
  211.     public static void main( String args[] ) throws FileNotFoundException
  212.      {
  213.          FittingAllgorithm application = new FittingAllgorithm();
  214.  
  215.         application.openFile();
  216.         application.addRecords();
  217.         application.place();
  218.         application.closeFile();
  219.      } // end main
  220.   } // end class CreateTextFile
  221.  
  222.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. public class Job
  4.   {
  5.       private int account;
  6.       private int account1;
  7.       private int account2;
  8.       private int account3;
  9.  
  10.      public Job()
  11.      {
  12.         // constructor
  13.      } 
  14.  
  15.  
  16.      public Job( int acct, int account11, int  account22, int account33 )
  17.      {
  18.         setAccount( acct );
  19.         setaccount1( account11 );
  20.         setaccount2( account22 );
  21.         setaccount3( account33 );
  22.      }
  23.  
  24.  
  25.      public void setAccount( int acct )
  26.      {
  27.         account = acct;
  28.      } 
  29.  
  30.  
  31.      public int getAccount()
  32.     {
  33.         return account;
  34.      }
  35.  
  36.  
  37.      public void setaccount1( int account11 )
  38.      {
  39.         account1 = account11;
  40.      }
  41.  
  42.  
  43.      public int getaccount1()
  44.      {
  45.         return account1;
  46.      } 
  47.  
  48.      public void setaccount2( int account22 )
  49.      {
  50.         account2 = account22;
  51.      } 
  52.  
  53.  
  54.      public int  getaccount2()
  55.      {
  56.         return account2;
  57.      }
  58.  
  59.  
  60.      public void setaccount3( int account33 )
  61.      {
  62.         account3 = account33;
  63.      } 
  64.  
  65.  
  66.      public int getaccount3()
  67.      {
  68.         return account3;
  69.     } 
  70.   } 
  71.  
  72.  
  73.  
  74.  
  75.  
Oct 16 '07 #3
r035198x
13,262 MVP
Read this article.

What do you mean by the total of the job greater than 100kb? Do you mean that the file size should not exceed 100kb?
Oct 16 '07 #4
kamsmartx
20 New Member
Read this article.

What do you mean by the total of the job greater than 100kb? Do you mean that the file size should not exceed 100kb?

yes i wont to size of my file 100 kb
how can i do
or can u write code of this
Oct 16 '07 #5
kamsmartx
20 New Member
ok
i see the article
but my code is true
but there are code that it saved any data on file
how write this code
Oct 16 '07 #6
r035198x
13,262 MVP
yes i wont to size of my file 100 kb
how can i do
or can u write code of this
Use the File class. Open the API specs for it. It has a method for determining the size of a file. Just check your file's current size before adding data to it.
Oct 16 '07 #7
kamsmartx
20 New Member
ok
but i dont have it is
can u write code
Oct 16 '07 #8
kamsmartx
20 New Member
i canot have API specs
Oct 16 '07 #9
r035198x
13,262 MVP
ok
but i dont have it is
...
What do you not have?
ok
..
can u write code
Some people think I can and some people think I can't ...
You'll have to write this yourself. We are here only to help you when you get stuck.
Oct 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2032
by: Sugapablo | last post by:
I have two ASP pages. They basically query a database, and spit out the information as plain text in CSV format. The first has the SQL query hardcoded into it. The second takes a SQL query from a webform. Now, the hardcoded results, I can click "Save Page As" when the results come up and save it as a text file. The other, while it seems to be the same results exactly, gives me an
0
1685
by: Jörg Braun | last post by:
Hello NG, i have a problem With WebRequest! i want to download a htaccess saved file over a proxyconnetion with authentication. Download a file what is not saved with htaccess is no problem, download a htaccess saved file with out a proxy with authentication i also no problem, but download this file with htaccess and the auth proxy is a prob!
4
2423
by: harvie wang | last post by:
In .Net,Through System.Configuration.ConfigurationSettings Get Application's Settings I can't find the Configuration Value from Register Where the ConfigurationSettings saved? How to Read it except System.Configuration? Thanks! Harvie
2
1897
by: mchamsters | last post by:
Just want to rant about something horrible that happened to me tonight. It was my first time using the new Visual C#. I started a new project, coding away continuously for about 6 hours. I saved and executed my code multiple times. I'd assume the source files are saved safely somewhere, but I was wrong... My computer crashed and I had to reboot it, without saving the project (the .sln file). When I started my computer, the project and the...
9
9772
by: charliewest | last post by:
Hello - I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#) is there any way to temporarily save an image to a session object, and after running some other operations, later retrieve the image from the session object, convert it back to an image, and re-save it to the database? Thanks?
0
2234
by: Rich Wallace | last post by:
Hello all, Looking for suggestions and tips if possible. I have an application running on a file server that utilizes the FileSystemWatcher to trap when any Excel files are saved by a user. I then need to 'trap' the current file and generate an XML file from the data within the active spreadsheet. I have two issues so far with doing this... Issue 1: Once a file that is being watched is saved, I grab it using the
9
1669
by: Peter Proost | last post by:
Hi group, I've got a question about the size of a saved bitmap. What I need to do is open a bitmap if it needs resizing, resize and save it. This isn't a problem, but the problem I have is that the original image has got an 8 bit indexed pixelformat, but you can't create a graphics object for this pixelformat so my bitmap uses the default pixelformat: Format32bppArgb, but this ofcourse result in a much larger file size (420kB instead of...
15
1909
by: Sharon | last post by:
I have an XML question: I'm have an XML node of type PointF and when it's saved to a file by XmlDocument.Save(...) it saves as I expect it to be saved: <ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin> But on my boss laptop this XML node is saved as:
2
1320
by: nanaalwi | last post by:
Greetings, Currently im doing an invoice software in which it will automatically save all the data entered by the user into excel file. Then when the user click 'SAVE' button, the excel file will be saved. However, the size of the saved file is very big which is 1.46MB, but if the data is inserted manually into excel (without using the software), the size is only approximately 60kB. Does anyone know what's the problem? Please Help... Your...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.