how to update the text file?

Ads
 

how to update the text file?

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

View Answers

Ads









Related Tutorials/Questions & Answers:
how to update the text file?
how to update the text file?
Advertisements
How to print differences of two text files
How to Convert Text Files into Gzip File
How can I Convert my Image Files to Text Files? - IDE Questions
Text Files
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how to update
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
How to update a file
Converting the text files into gzip file.
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
Converting Text Files into Bzip File
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to update image in php
save output in multiple text files
How to update table in Hibernate
how to update the value of jslider
how to update the value of jslider
how to update the value of jslider
how to update the value of jslider
how to update the value of jslider
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
How to update clob??
How Compare 2 xml files with JDOM - Java Beginners
How to list files in hadoop?
Converting the text files into bzip file.
how to update specific row in on update key in the Navicat for mysql trigger
how to update checkbox list in database
how to update table using inner joins
How to update mysql from 5.1 to 5.5

Ads