मैं FileOutputStream उपयोग कर रहा हूँ PrintStream साथ इस तरह:क्या मुझे FileOutputStream को बंद करना है जो प्रिंटस्ट्रीम द्वारा लपेटा गया है?
class PrintStreamDemo {
public static void main(String args[]){
FileOutputStream out;
PrintStream ps; // declare a print stream object
try {
// Create a new file output stream
out = new FileOutputStream("myfile.txt");
// Connect print stream to the output stream
ps = new PrintStream(out);
ps.println ("This data is written to a file:");
System.err.println ("Write successfully");
ps.close();
}
catch (Exception e){
System.err.println ("Error in writing to file");
}
}
}
इम समापन केवल PrintStream। क्या मुझे FileOutputStream (out.close();
) को बंद करने की आवश्यकता है?
स्रोत कोड देखें: http://www.docjar.com/html/api/java/io/PrintStream.java.html – jtoberon
वैसे, प्रिंटस्ट्रीम की सुंदरता यह तथ्य है कि आप इसका उपयोग केवल इसके साथ कर सकते हैं एक स्ट्रिंग (फ़ाइल नाम के लिए) या एक फ़ाइल ऑब्जेक्ट। प्रिंटस्ट्रीम में इसका उपयोग करने के लिए आपको केवल FOStream खोलने की आवश्यकता नहीं है। – Mechkov