# Java Scripts

**URL:** <https://forum.inductiveautomation.com/t/java-scripts/2227>\
**Category:** Ignition\
**Created:** [September 29, 2010, 2:35pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227 "2010-09-29T14:35:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 29, 2010, 2:35pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/1 "2010-09-29T14:35:12Z")

</div>

Ok, I’m porting some code over from java, and again I’m haing a problem figuring out what to pass in for parameters. In the following code, I get the “readAsBytes() takes at least 2 arguments (1 given)” error. How can I tell what it’s looking for?

```auto
from java.lang import Byte
from java.io import FileInputStream
from java.io import File
import jarray
import java.net

def readAsBytes(self,file):
	print 'ok'

url = java.net.URL("http://localhost:8088/Import/Test.txt")

B=readAsBytes(url)
```

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 29, 2010, 3:04pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/2 "2010-09-29T15:04:05Z")

</div>

What are you wanting the code to do? If you want to read the file as an array of bytes, there is an Ignition function to do this - system.file.readFileAsBytes(filepath).

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 29, 2010, 3:05pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/3 "2010-09-29T15:05:52Z")

</div>

Well your function has two arguments self and file. Just remove the self since it is not needed.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 29, 2010, 3:13pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/4 "2010-09-29T15:13:19Z")

</div>

Nope, I wasn’t aware of that. That just might do the trick. But, the point still stands- what is this looking for? I think it’s looking for a File object, and I tried instantiating one by passing in various flavors of java.io.newInstance(), but no-go. Just want to understand this a little better. (I’ve added a line of code in the function, and the rest will work if it gets past the File object).

```auto
from java.lang import Byte
from java.io import FileInputStream
from java.io import File
import jarray
import java.net

def readAsBytes(self,file):
	f = File(file)

url = java.net.URL("http://localhost:8088/Import/Test.txt")

B=readAsBytes(url)
```

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 29, 2010, 3:15pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/5 "2010-09-29T15:15:54Z")

</div>

> [@Travis.Cox](#):
>
> Well your function has two arguments self and file. Just remove the self since it is not needed.

I tried that too, but then the "f = File(file)" fails. As I mentioned above, I think it's looking for a file object.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 29, 2010, 3:24pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/6 "2010-09-29T15:24:04Z")

</div>

Yes it will because the function does not have the Java File imported. You need to place the imports inside the function:[code]from java.lang import Byte  
import jarray  
import [java.net](http://java.net)

def readAsBytes(file):  
from [java.io](http://java.io) import File  
from [java.io](http://java.io) import FileInputStream  
f = File(file)

url = java.net.URL(“[http://localhost:8088/Import/Test.txt](http://localhost:8088/Import/Test.txt)”)

B=readAsBytes(url)[/code]

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 29, 2010, 5:01pm UTC](https://forum.inductiveautomation.com/t/java-scripts/2227/7 "2010-09-29T17:01:30Z")

</div>

Yep, removing “self” and adding the imports did the trick. Thanks!
