473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

saved to file

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 1789
r035198x
13,262 8TB
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
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 8TB
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
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
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 8TB
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
ok
but i dont have it is
can u write code
Oct 16 '07 #8
i canot have API specs
Oct 16 '07 #9
r035198x
13,262 8TB
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
r035198x
13,262 8TB
i canot have API specs
Of course you can. Here's a link to the specs for the File class.
Better still, you can download the whole thing from the link in this index.
Oct 16 '07 #11
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.
i dont do it
????????????
Oct 16 '07 #12
r035198x
13,262 8TB
i dont do it
????????????
You are no longer any sense. What do you mean by "i don't do it"?
Oct 16 '07 #13
mmmmmmmmmm

idont write the code
i need to saved data on my file how?????????
Oct 16 '07 #14
r035198x
13,262 8TB
mmmmmmmmmm

idont write the code
i need to saved data on my file how?????????
So who writes the code? You want to save data to the file without writing the code?

P.S You only need to type each ? once.
Oct 16 '07 #15
So who writes the code? You want to save data to the file without writing the code?

P.S You only need to type each ? once.
i need code to saved the data
Oct 16 '07 #16
i need code to saved the data
help >>>>>>>>>>>>>>>>>>
Oct 16 '07 #17
any help place
oh
help meeeeeeeeee
Oct 16 '07 #18
r035198x
13,262 8TB
any help place
oh
help meeeeeeeeee
Stop this. You are going nowhere with it.
We won't write the codes for you here. We'll just help you if you are stuck with the code. Now I've pointed you to the File class and an article that explains how to read and write to a file. What's your problem now?
Oct 16 '07 #19
pbmods
5,821 Expert 4TB
kamsmartx, the next post you make will be the code that YOU wrote to attempt to solve your problem, or else I'm closing this thread.

TSDN members are expected to write their own code. We're happy to help you out if you have specific questions, but you can't realistically expect someone to do your coding for you on a free forum.
Oct 16 '07 #20
r035198x
13,262 8TB
kamsmartx, the next post you make will be the code that YOU wrote to attempt to solve your problem, or else I'm closing this thread.

TSDN members are expected to write their own code. We're happy to help you out if you have specific questions, but you can't realistically expect someone to do your coding for you on a free forum.
I'm afraid this thread is leaning itself towards Jos' law ...
Oct 16 '07 #21
JosAH
11,448 Expert 8TB
@OP: I'm afraid we have a language problem here: your command of the English
language is not enough to tell us exactly what your problem is. I'm nog trying to
offend you nor anybody else, but this is not going to work out.

Would it be possible if someone else (having a better grip on the English language)
asks your question on your behalf?

kind regards,

Jos
Oct 16 '07 #22

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

Similar topics

0
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...
0
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,...
4
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...
2
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...
9
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...
0
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...
9
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...
15
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,...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.