ืืื ืืืืงืช PrintWriter ื-Java?
ืืืืข ืืืฉืชืืฉ ื-PrintWriter ืื OutputStreams ืืืจืื ืืืื ืื?
ืื ืืื ืื ืคืืฅ ืืืืชืจ ืืืืคืกืช ื ืชืื ืื ืขื ืืืกืืฃ ืืื ืืืืฆืขืืช ืฉืืืช System.out.print . ืขื ืืืช, ืงื ืืืชืจ ืืืชืืื ืืืฉืืช ืืช ืืคืืจืื ืืคื ืืืงืื ืฉืฆืืื (ืชืงื ืื ืืืืจืืื ) ืชืื ืคืจืกืื ืืืฉืืืื ืืืืืืืื ืืืืฆืขืืช ืืืืืืืงื PrintWriter . ืื ื ืืืืืื ืืืืื ืืช ืืฉืืืืฉ ื-Locale ืืืชืื ืืืขืจืืช ืฉืื ืืืืฉื ืืคืืกื ืืื.ืืืฆื ืืืฉืชืืฉ ืืืืชื PrintWriter?
ืืื ืืืฉืชืืฉ ื- PrintWriter , ืขืืื ืืืืื ืืช ืืืืืงื java.io.PrintWriter . ืืืืจ ืืื ืืืืจ ืืชืืื ืืืืืืืงื ืฉืื, ืืชื ืืืื ืืืฉืชืืฉ ืื ืืืชืืื ืืงืื ืกืืื ืื ืืงืืืฅ ืืคื ืืฆืจืืื ืฉืื. ืืืื ื ืกืชืื ืขื ืฉืชื ืืืจืืื ืืืชืืื ืฉื ืืืืงืช PrintWriter ืขืืืจ ืืืกืืฃ ืืืงืืืฅ. ืงืืืืื ืืกืคืจ ืื ืืื ืฉืื ืื. ืืื ืืื ื ืฆืื ืืคื ืืื ืืช ืืคืฉืืืื ืฉืืื, ืืืืชืืืื.ืคืื ืืกืืฃ ืขื PrintWriter
ืืืื ืืืืืืงื PrintWrtier ืืืืคืกืช ืืงืกื ืขื ืืืกืืฃ.PrintWriter consoleOutput = new PrintWriter(System.out);
ืืื ืืืืืืืงื System.out ืืืขืืจ ืืื ืื ืืืชืืื ืืงืื ืกืืื.
ืคืื ืงืืืฅ ืขื PrintWriter
ืื ื ืืืืืืงื PrintWriter ืืืชืืืช ืืงืกื ืืงืืืฅ.PrintWriter fileOutput = new PrintWriter("FileOutput.txt");
ืื ืื ืื ืืืงื ืงืื ืืืจืืืช ืืฉื ืืงืืืฅ. ืืืฆืจ ืงืืืฅ ืืฉื ืฉืฆืืื ืืืืชื ืื ืืช ื ืชืื ื ืืืงืกื.
ืฉืืืืช ืฉื ืืืชืช PrintWriter
ืืืืงืช Java PrintWriter ืืืืขื ืขื ืฉืื ืฉืืืืช ืฉืืืืฉืืืช. ืงืฉื ืืืชืจ ืืืืืข ืจืง ืขื ืืื ืืืืกื. ืื, ืืืื ื ืจืื ืื ืืื ืืืืืื. ืื ืื, ืืืืฆื ื ืืื ืืืฉืชืืฉ ืืื ืืงืืืช.ืืืืื 1
ืืืืื ืื ืชืืืื ืฉืืืืฉ ืืืืืืืงื PrintWriter ืืืืคืกื ืขื ืืืกืืฃ.import java.io.PrintWriter;
public class PrintWriterDemo {
public static void main(String[] args) throws Exception {
// by importing the java.io.PrintWriter class
PrintWriter consoleOutput = new PrintWriter(System.out);
consoleOutput.printf("Hey there! This is %S.\n", "Lubaina Khan");
consoleOutput.print("Today you're exploring the PrinWriter class with Code Gym. ");
consoleOutput.println("Hope you're having fun!");
consoleOutput.append("Patience is the key when learning new concepts.\n");
consoleOutput.append("It all boils down to practise and persistence. :)");
consoleOutput.flush();
consoleOutput.close();
}
}
ืชึฐืคืึผืงึธื
ืฉืืื! ืื LUBAINA KHAN. ืืืื ืืชื ืืืื ืืช ืฉืืขืืจ PrinWriter ืขื Code Gym. ืืงืืื ืฉืืชื ื ืื ื! ืกืืื ืืช ืืื ืืืคืชื ืืืฉืจ ืืืืืื ืืืฉืืื ืืืฉืื. ืืื ืืกืชืื ืืชืจืืื ืืืชืืื. :)
ืฉืืืืช ืืฉืืืฉืืช ืฉื PrintWriter Class
printf(String str, Object arguments);
ืืฉืืื printf () ืืืงืืช ืืช ืืคืืจืื ืฉื ืืืืจืืืช ืืืืคืืก. ืืื, ืืฆืืื ืืืืงืื %S ืืืืืฃ ืืืจืืืื ื ืืืืชืืืช ืืืืขืืจ ืืฆื ืืืืจืืืช.
print(String str);
ืฉืืื ืื ืชืืคืืก ืืช ืืืืจืืืช ืืืืขืืจืช ืืืื ืืืืฆืขืืช ืืืืืืืงื PrintWriter .
println(String str);
ืืขืืจ ืฉืืจื ืืืืคืก ืืืจื ืชืืื ืืืืจืืืช.
append(CharSequence cs);
ืจืฆืฃ ืืชืืืื ืืืืขืืจ ื-append ืืชืืืกืฃ ืืืืืืืงื PrintWrtier .
flush();
ืืจืืงื ืืช ืืชืืื ืฉื ืืืืืืืงื PrintWriter .
close();
ืกืืืจ ืืช ืืจื ืืืชืืื ืืืฉืืจืจ ืืช ืื ืืืฉืืืื ืฉืืืงืฆื.
ืืืืื 2
ืืืืื ืื ืชืฆืื ืืช ืืฉืืืืฉ ืืืืืงื PrintWriter ืืืชืืืช ื ืชืื ืื ืืงืืืฅ.import java.io.PrintWriter;
import java.util.Date;
import java.util.Locale;
public class PrintWriterDemo {
public static void main(String[] args) throws Exception {
try {
// by importing the java.io.PrintWriter class
PrintWriter fileOutput = new PrintWriter("FileOutput.txt");
fileOutput.printf(Locale.getDefault(), "Hi, What's the day today? %s.\n", new Date());
fileOutput.print("Here's an implementation of PrinWriter class for file writing.\n");
fileOutput.println("Hope Code Gym made it simpler for you to understand.");
fileOutput.append("One step at a time, and off you go!", 0, 35);
fileOutput.flush();
fileOutput.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
ืชึฐืคืึผืงึธื
ืืื, ืื ืืืื ืืืื? ืืื ืจืืฉืื 25 ืืืืื 17:30:21 PKT 2021. ืื ื ืืืฉืื ืฉื ืืืืงื PrinWriter ืืืชืืืช ืงืืฆืื. ืืงืืื ืฉ-Code Gym ืขืฉื ืื ืืช ืื ืคืฉืื ืืืชืจ ืืืืื. ืฆืขื ืืื ืืื ืคืขื, ืืืชื ืืืฆื ืืืจื!
ืฉืืืืช ืืฉืืืฉืืช ืฉื PrintWriter Class
ืืืื ื ืืื ืืฉืืืืช ืืืฉืืฉืืช ืืืชืืืช ืงืืฆืื ืืืืืืืืช ืืืชืืื ืืงืื ืกืืื.printf(Locale locale, String str, Object args);
ืืื ืืชื ืืืื ืืืขืืืจ ืืช ืืืงืื (ืืฉืชืืฉื ื ืืืจืืจืช ืืืืื ืฉื ืืืขืจืืช ืขืืืจ ืงืืืจื ืืืืช) ืืชื ืืืื ืืืฉืชืืฉ ืืื ืืื ืืคื ืืฆืจืืื ืฉืื. ืื ืชืืื ืืื ืขืืฆืื ืืืืกืก ืืืืจ. ืฉืืจ ืืืืฉืื ืืื ืืื ืฉืืื ืืฉืืืืฉ ืงืืื.
append(CharSequence cs, int beginningIndex, int endingIndex);
ืืชื ืืืื ืืืืกืืฃ ืืืง ืื- CharSequence ืฉืขืืจ ืขื ืืื ืฆืืื ืืื ืืงืก ืืืชืืื ืืืกืืื ืฉืื. ืืื ืืฉืชืืฉื ื ืืืื ืืงืก ืืืืจืื. ืืชื ืืืื ืืฉืืง ืขื ืื ืืื ืืจืืืช ืคืืืื ืฉืื ืื.
try{
...
} catch (Exception e){
...
}
ืืืืง ื-Try-catch ืืฉืืฉ ืืืืจื ืืืชืืืช ืืงืืืฅ. ืื ืืื ืืื ืืข ืืจืืืื ืืืฉืื ืืืื ืืืฉื (ืืืฉื, ืืขืืืช ืืจืฉืืืช) ืื ืืฆืืจืช ืืงืืืฅ ืืืขืจืืช.
GO TO FULL VERSION