Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to update the text file?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kranti kumar
how to update the text file?
0 Answer(s)      4 years ago
Posted in : Java Beginners


my textfile with name list.txt: Rice 25.0 500 Wheat 80.0 150 Jowar 50.0 150 .... ....20 lines.

java code: import java.io.*; import java.util.*; class New { String item; double price; float quantity; New(String item,double price,float quantity) { this.item=item; this.price=price; this.quantity=quantity; } float test(String str,float f) { if(str.equalsIgnoreCase(item)) { System.out.println("item is present"); if(quantity>=f) quantity=quantity-f;

     else
 System.out.println("no stock");
    }

else{


     quantity=-1;
        }

return quantity;

}public void display() { System.out.println(item+","+price+" ,"+quantity+"\n"); } public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the list of items u need"); int n1=Integer.parseInt(br.readLine()); String[] item=new String[n1]; float[] quantity=new float[n1];

for(int i=0;i File file ; FileReader fr=null ; FileWriter fw; Scanner sc=null; Scanner sc1=null; try{

            file = new File("list.txt");
            fr = new FileReader(file); 
            fw= new FileWriter(file);
            sc = new Scanner(fr);
            sc1=new Scanner(fw);

for(int i=0;i<20;i++) { n[i]=new New(sc.next(),sc.nextDouble(),sc.nextFloat());

} for(int j=0;j }

          finally {
          fr.close();
          sc.close();

} }} now i want to update the quantity in my text file, if the item i entered matches with item in text file.how can i do it?please suggest any answer


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com