how to generate text file named as a user's name while generating receipt for him/her when he purchases a book,in java console based application.Help me out.
Asked
Active
Viewed 57 times
-2
-
Does http://stackoverflow.com/a/797569/7724 help? – bzlm Dec 01 '14 at 11:19
-
You are more likely to get help if you provide all the relevant code. – Magnilex Dec 01 '14 at 11:22
1 Answers
0
import java.io.File;
import java.io.FileOutputStream;
import java.util.Scanner;
public class BookApplication {
public static void main(String[] args) {
try {
System.out.println("Hi , Enter Your Name ?");
Scanner scanner =new Scanner(System.in);
String username= scanner.nextLine();
String MY_OUTPUT_PATH="";//your path where you want your file
boolean bookPurchased=true; // Do your code for bookpurchase
if(bookPurchased){
File receipt= new File(MY_OUTPUT_PATH+ File.separator+username+".txt");
FileOutputStream outputStream =new FileOutputStream(receipt);
String sampleData=username+" has purchased a book for rs.500";
outputStream.write(sampleData.getBytes());
outputStream.close();
}
} catch (Exception e) {
System.out.println(e);
}
}
}
This is what I can give you from your Question. Try working on what you want, then ask Questions.
Arun Xavier
- 763
- 8
- 47
-
-
post your code somewhere and give its link show how you are getting this dynamic input, show your applications flow – Arun Xavier Dec 02 '14 at 05:30