Last active
August 4, 2024 17:03
-
-
Save akexorcist/10010827 to your computer and use it in GitHub Desktop.
ฟังก์ชันเขียนไฟล์ txt ธรรมดาๆ โดยมีแบบเขียนทับหรือเขียนต่อจากเดิม
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void appendTextFile(String text) { | |
File file = new File("sdcard/text.txt"); | |
if (!file.exists()) { | |
try { | |
file.createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
try { | |
BufferedWriter buf = new BufferedWriter(new FileWriter(file, true)); | |
buf.append(text); | |
buf.newLine(); | |
buf.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void createTextFile(String text) { | |
File file = new File("sdcard/text.txt"); | |
if (!file.exists()) { | |
try { | |
file.createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
try { | |
BufferedWriter buf = new BufferedWriter(new FileWriter(file, false)); | |
buf.append(text); | |
buf.newLine(); | |
buf.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
pip install requests
pip install requests
pip install requests
> pip install requests
``
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
123