import java.util.*;
import java.io.*;
public class ProductInfoDwnld{
static String abc;
public static void addProductToCart(String a_CartId, String a_productId, String a_desc, String a_price){
BufferedWriter bw = null;
try{
File yourFile = new File(a_CartId);
// Check if yourFile exists
if(!yourFile.exists())
yourFile.createNewFile(); // Create a new yourFile if it does not exist
else{
try {
FileWriter fileWrite = new FileWriter(yourFile,true);
fileWrite.write(a_productId + " " + a_desc + " " + a_price); // write(String str);
fileWrite.close();
}catch (IOException ioe) {
ioe.printStackTrace();
}
}
FileOutputStream oFile = new FileOutputStream(yourFile,false);
}catch(Exception e){
System.out.println("Error");
}
}
public static void main(String[] args){
String CartID = "001.txt";
String productId="001", Desc = "Laptop", price="20000Rs";
addProductToCart(CartID,productId,Desc,price);
}
}
以下のコードを使用して、FileWriter クラスを使用してファイル 001.txt に書き込もうとしています。しかし、データはファイルに書き込まれていません。理由がわかりません。助けが必要