Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

how to update the text file?



Share on Google+Share on Google+

kranti kumar
how to update the text file?
0 Answer(s)      6 years and 8 months 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*; 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;

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



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.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.nextDouble(),sc.nextFloat());

} for(int j=0;j }

          finally {

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

View Answers

Related Tutorials/Questions & Answers: