So you want to files, huh? M'kay.
Example code:
import java.io.IOException;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(author = "", info = "", logo = "", name = "Chicken Killer", version = 0)
public class ChickenKiller extends Script {
OSBotFileAPI osbotFile;
String profile;
@Override
public void onStart() throws InterruptedException {
initialiseCustomAPIs();
iWantToOpenAFile();
iWantToSaveStuffToAFile("Hello world!");
}
private void initialiseCustomAPIs() {
osbotFile = new OSBotFileAPI();
osbotFile.exchangeContext(bot);
osbotFile.initializeModule();
}
private void iWantToOpenAFile() {
try {
profile = osbotFile.open();
logger.debug(profile);
} catch (RuntimeException | IOException e) {
logger.error(e);
}
}
private void iWantToSaveStuffToAFile(String stuff) {
try {
osbotFile.save("Hello world!");
} catch (RuntimeException | IOException e) {
logger.error(e);
}
}
@Override
public int onLoop() throws InterruptedException {
return 250;
}
}
Testing:
Folder is automatically created if it doesn't exist:
I manually created a text file for testing and added it into the script data folder:
I re-ran the script so that I could now select something:
And then the script did a little save testing with the same file:
Functions:
public boolean folderExists()
protected synchronized String readFromFile(File file) throws FileNotFoundException, IOException
public synchronized String readFromFile(String filename) throws FileNotFoundException, IOException
protected synchronized void writeToFile(File file, String fileContent) throws IOException
public synchronized void writeToFile(String filename, String fileContent) throws IOException
public synchronized String open(FileFilter fileFilter) throws RuntimeException, FileNotFoundException, IOException
public synchronized String open() throws RuntimeException, FileNotFoundException, IOException
public synchronized void save(FileFilter fileFilter, String fileContent) throws IOException
public synchronized void save(String fileContent) throws IOException
public synchronized boolean deleteFile(String filename)
Source: