ืžื”ื™ ืžื—ืœืงืช PrintWriter ื‘-Java?

"PrintWriter ื”ื™ื ืžื—ืœืงื” ื”ืžืฉืžืฉืช ืœื›ืชื™ื‘ืช ื›ืœ ืฆื•ืจื” ืฉืœ ื ืชื•ื ื™ื ื›ื’ื•ืŸ int, float, double, String ืื• Object ื‘ืฆื•ืจื” ืฉืœ ื˜ืงืกื˜ ืื• ื‘ืงื•ื ืกื•ืœื” ืื• ื‘ืงื•ื‘ืฅ ื‘-Java."
ืœื“ื•ื’ืžื”, ืืชื” ื™ื›ื•ืœ ืœื”ืฉืชืžืฉ ื‘ืื•ื‘ื™ื™ืงื˜ PrintWriter ื›ื“ื™ ืœืจืฉื•ื ื ืชื•ื ื™ื ื‘ืงื•ื‘ืฅ ืื• ืœื”ื“ืคื™ืก ืื•ืชื ื‘ืžืกื•ืฃ.

ืžื“ื•ืข ืœื”ืฉืชืžืฉ ื‘-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 ืžืฉืžืฉ ื‘ื”ื›ืจื— ื‘ื›ืชื™ื‘ืช ื”ืงื•ื‘ืฅ. ื–ื” ื›ื“ื™ ืœืžื ื•ืข ื—ืจื™ื’ื™ื ื›ืœืฉื”ื ื‘ื–ืžืŸ ื’ื™ืฉื” (ืœืžืฉืœ, ื‘ืขื™ื•ืช ื”ืจืฉืื•ืช) ืื• ื™ืฆื™ืจืช ื”ืงื•ื‘ืฅ ื‘ืžืขืจื›ืช.

ืกื™ื›ื•ื

ื–ื” ื”ื™ื” ื”ืงื“ืžื” ืžื”ื™ืจื” ืœืฉื™ืžื•ืฉ ื‘-Java PrintWriter Class. ืžืงื•ื•ื” ืฉื–ื” ืœื ื”ื™ื” ืžื”ืžื ืขื‘ื•ืจืš. ืื ื›ืŸ, ืื ื• ืžืžืœื™ืฆื™ื ืœื”ื‘ื™ืŸ ื›ืœ ื›ื•ืชืจืช ื•ืœืชืจื’ืœ ืชื•ืš ื›ื“ื™ ื”ืžืฉืš. ืืชื” ืชืžื™ื“ ืžื•ื–ืžืŸ ืœื—ื–ื•ืจ ืœืžืงืจื” ืฉืœ ืžื›ืฉื•ืœื™ื. ืชืžืฉื™ืš ืœืฉืื•ืœ ื•ืชืžืฉื™ืš ืœื’ื“ื•ืœ.