Bitwig Java API: Writing to a text file

Post Reply New Topic
RELATED
PRODUCTS

Post

Hi, I'm trying to write stuff from the Bitwig Java API to a text file on Windows.
I tried to use

Code: Select all

import java.io.FileWriter
but always get the exceptions when trying

Code: Select all

try {
	fileWriter = new FileWriter("filename.txt");
} catch (Exception e) {
	host.println("file writer open error");
}

Code: Select all

try {
	fileWriter.write("some text");
} catch (Exception e) {
	host.println("file writer write error");
}

Code: Select all

try {
	fileWriter.close();
} catch (Exception e) {
	host.println("file writer close error");
}
Should that normally work? Or is there maybe some permission error? Have someone already found good solution?

Post

u-u-u wrote: Wed Jun 17, 2020 5:30 am Hi, I'm trying to write stuff from the Bitwig Java API to a text file on Windows.
I tried to use

Code: Select all

import java.io.FileWriter
but always get the exceptions when trying

Code: Select all

try {
	fileWriter = new FileWriter("filename.txt");
} catch (Exception e) {
	host.println("file writer open error");
}

Code: Select all

try {
	fileWriter.write("some text");
} catch (Exception e) {
	host.println("file writer write error");
}

Code: Select all

try {
	fileWriter.close();
} catch (Exception e) {
	host.println("file writer close error");
}
Should that normally work? Or is there maybe some permission error? Have someone already found good solution?
If your current directory is the Bitwig program folder it won't work. Simply look at what the content of the exception tells you.

Post

moss wrote: Wed Jun 17, 2020 6:43 am
u-u-u wrote: Wed Jun 17, 2020 5:30 am Hi, I'm trying to write stuff from the Bitwig Java API to a text file on Windows.
[...]
If your current directory is the Bitwig program folder it won't work. Simply look at what the content of the exception tells you.
Hey Moss, thank you for your answer!

I checked and yes, the current directory is the Bitwig program folder. So I tried to change it temporarily (following this solution) before and after the file write operation:

Code: Select all

//store the current directory:
String originalDir = System.getProperty("user.dir");
//change directory to documents folder for example:
System.setProperty("user.dir", "C:\\Users\\[...]\\Documents");

//placeholder: put file creation/write operation here

//change the directory back to original:
System.setProperty("user.dir", originalDir);
But I unfortunately I still get an AccessDeniedException :(
So I assume that it's simply not possible ATM :?:


EDIT: Seems like it kinda works now. Have to investigate a bit further. I'll leave some comment...

Post

u-u-u wrote: Wed Jun 17, 2020 4:43 pm
moss wrote: Wed Jun 17, 2020 6:43 am
u-u-u wrote: Wed Jun 17, 2020 5:30 am Hi, I'm trying to write stuff from the Bitwig Java API to a text file on Windows.
[...]
If your current directory is the Bitwig program folder it won't work. Simply look at what the content of the exception tells you.
Hey Moss, thank you for your answer!

I checked and yes, the current directory is the Bitwig program folder. So I tried to change it temporarily (following this solution) before and after the file write operation:

Code: Select all

//store the current directory:
String originalDir = System.getProperty("user.dir");
//change directory to documents folder for example:
System.setProperty("user.dir", "C:\\Users\\[...]\\Documents");

//placeholder: put file creation/write operation here

//change the directory back to original:
System.setProperty("user.dir", originalDir);
But I unfortunately I still get an AccessDeniedException :(
So I assume that it's simply not possible ATM :?:


EDIT: Seems like it kinda works now. Have to investigate a bit further. I'll leave some comment...
I think you should read a bit how the File class works and what are relative and absolute paths. Also how to do exception handling would be helpful.

Post Reply

Return to “Controller Scripting”