Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.RandomAccessFile;
- import java.nio.channels.FileChannel;
- import java.nio.channels.FileLock;
- public class Methods {
- static String path = System.getProperty("user.home") + File.separator
- + "OSBot" + File.separator + "data" + File.separator + "btm.txt";
- /*
- * Method needs to be used like so ScriptName,Accname,XP Gained,Xp-per-hour
- */
- public static void addAccount(String setting)
- throws IOException {
- File file = new File(path);
- FileWriter f = new FileWriter(file, true);
- RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
- FileChannel channel = randomAccessFile.getChannel();
- FileLock lock = channel.lock();
- f.write(setting + System.getProperty("line.separator"));
- lock.release();
- channel.close();
- randomAccessFile.close();
- f.close();
- }
- public static boolean statsAreValid() {
- return (new File((path)).exists());
- }
- public static void removeAccount(String acc) throws IOException {
- if (statsAreValid()) {
- FileInputStream fstream = new FileInputStream(path);
- BufferedReader br = new BufferedReader(new InputStreamReader(
- fstream));
- String strLine;
- StringBuilder fileContent = new StringBuilder();
- while ((strLine = br.readLine()) != null) {
- String lines[] = strLine.split(",");
- if (lines[1].equalsIgnoreCase(acc)) {
- fileContent.append("");
- } else {
- fileContent.append(strLine + System.lineSeparator());
- }
- }
- FileWriter fstreamWrite = new FileWriter((path));
- BufferedWriter out = new BufferedWriter(fstreamWrite);
- out.write(fileContent.toString());
- out.close();
- br.close();
- }
- }
- public static void updateAccount(String account_name, String settings)
- throws IOException {
- FileInputStream fstream = new FileInputStream(path);
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- StringBuilder fileContent = new StringBuilder();
- while ((strLine = br.readLine()) != null) {
- String lines[] = strLine.split(",");
- if (lines[1].equalsIgnoreCase(account_name)) {
- String newLine = settings;
- fileContent.append(newLine + System.lineSeparator());
- } else {
- fileContent.append(strLine + System.lineSeparator());
- }
- }
- FileWriter fstreamWrite = new FileWriter((path));
- BufferedWriter out = new BufferedWriter(fstreamWrite);
- out.write(fileContent.toString());
- out.close();
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement