how to update the text file?

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









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 search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
How to Convert Text Files into Gzip File
ModuleNotFoundError: No module named 'filee'
ModuleNotFoundError: No module named 'filem'
ModuleNotFoundError: No module named 'filez'
Text Files
ModuleNotFoundError: No module named 'filex'
ModuleNotFoundError: No module named 'filex'
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
How can I Convert my Image Files to Text Files? - IDE Questions
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
How to update a file
Converting Text Files into Bzip File
Converting the text files into gzip file.
save output in multiple text files
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
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
Converting the text files into bzip file.
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 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 update clob??
ModuleNotFoundError: No module named 'filer'
how to update specific row in on update key in the Navicat for mysql trigger
How Compare 2 xml files with JDOM - Java Beginners
How to list files in hadoop?
update
How to make a cloudy text, cloudy text, text
org.commonjava.indy - indy-filer-default version 1.2.2 Maven dependency. How to use indy-filer-default version 1.2.2 in pom.xml?
org.commonjava.indy - indy-filer-default version 1.1.7 Maven dependency. How to use indy-filer-default version 1.1.7 in pom.xml?
how to update checkbox list in database
ModuleNotFoundError: No module named 'flask-filer'
ModuleNotFoundError: No module named 'flask-filer'
ModuleNotFoundError: No module named 'flask-filer'
ModuleNotFoundError: No module named 'fluentcms-filer'
ModuleNotFoundError: No module named 'cmsplugin-filer'
ModuleNotFoundError: No module named 'django-filer'
ModuleNotFoundError: No module named 'flask-filer'

Ads