Misol: Java FileOutputStream yordamida mag'lubiyatga oid ma'lumotlarni yozing
Shuningdek, biz qatorni baytlar qatoriga aylantirishimiz va ma'lumotlarni ko'rsatilgan joyga yozishimiz mumkin Fayl Java FileOutputStream sinfidan foydalanish. Quyida satrni faylga yozish misoli keltirilgan.
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteFile {
public static void main(String[] args) throws FileNotFoundException {
FileOutputStream fo = new FileOutputStream("OutputFile.txt");
String text = "Welcome to Java programming";
try {
byte[] b = text.getBytes();
fo.write(b);
fo.close();
System.out.println("String data successfully written to the file");
} catch (IOException e) {
e.printStackTrace();
}
}
}
String data successfully written to the file
Do'stlaringiz bilan baham: |