Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Some IO Help Needed, on a project..  (Read 1942 times)
0 Members and 1 Guest are viewing this topic.
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Posted 2006-12-01 19:34:07 »

Hei!

im doing my very first Java file IO function Grin, function is almost an copy/paste
of  suns java IO tutorials but i failed to do an all way working function..

my question is how to make 'getCodeBase()' function to work with my project??   Huh

FileInputStream in = new FileInputStream (getCodeBase()+"xanadu.txt");       returns an red liner on code..

//----

public void copyBytes () throws IOException
{   
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream ("c:/xanadu.txt");
            out = new FileOutputStream("c:/outagain.txt");
            int c;

            while ((c = in.read()) != -1) {
                out.write(c);
            }

        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
}

//----
Offline Kova

Senior Devvie





« Reply #1 - Posted 2006-12-01 23:00:04 »

When you got errors it's wise to mention them also so we can know what is wrong.
furthermore you provided copyBytes() while we need to see getCodeBase() instead.
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Reply #2 - Posted 2006-12-02 11:08:07 »

Hei!

When you got errors it's wise to mention them also so we can know what is wrong.
furthermore you provided copyBytes() while we need to see getCodeBase() instead.

were sorry, here is it, the error..

//------------------

FileInputStream in = new FileInputStream (getCodeBase()+"xanadu.txt");       returns an red liner on code and the following error.. Huh Huh Huh

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Jari Tapio\FullScreenTest\build\classes
C:\Documents and Settings\Jari Tapio\FullScreenTest\src\fullscreentest\MultiBufferTest.java:82: cannot find symbol
symbol  : method getCodeBase()
location: class MultiBufferTest
            in = new FileInputStream (getCodeBase ()+"xanadu.txt");
1 error
BUILD FAILED (total time: 5 seconds)

//------------------
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Devvie





« Reply #3 - Posted 2006-12-02 17:45:38 »

lol

listen, start reading basic java tutorials and books, something in general about java language. Only when you know the basics you should come back and try to make a game. This is a forum for developing games in java, we won't teach you how to program java here.

About your error, you are trying to use a method that does not exist. Like, it's not there, you didn't wrote/code it.
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Reply #4 - Posted 2006-12-02 19:28:10 »

Hei!

Kova wrote :

//----------------------

lol

listen, start reading basic java tutorials and books, something in general about java language. Only when you know the basics you should come back and try to make a game. This is a forum for developing games in java, we won't teach you how to program java here.

//----------------------

'listen, start reading basic java tutorials and books.. blahblah..'
well, that was a good advice, thanks, as i am a very novice on Java i need to know where to start,
what sites do you people recommend to me and what sites are good to take to my bookmarks, thanks. Cheesy

'...only when you know basics you should come back and try to make a game..' Undecided
well, this was an bit of a unpolite from you, and knowing basics is a complicated thing,
i can say to you that i do know a basics about game programming but i just dont know
how to read a file from a Java '/build/class/'  directory getCodeBase () didnt work..

'..This is a forum for developing games in java, we won't teach you how to program java here..' Tongue
well, im after a game and what i think is that people do teach how to program Java in here
(bufferedimage is a popular thing on this forum then why not 'FileInputStream')??

 Grin and cos ya were thinking that i cant make a real game then here is one for you its my visualc++ cavegame and im doing
it currently to Java hopely you like it, i need to know how to read those level files from my '/build/classes' directory to
make my Java version roll with those old c++ levels..
..
www.5mingames.eurojari.net/CaveGame99.zip

hope you liked it, i will publish it on my webpage later, i made it at 1999, if you played my game
you can understand that i can say that i am a hobby game developer and i just need to learn some basics,
liked you said, of Java and i was thinking that this forum would be right place to start doing it and doing it with
real people, hopely i was not wrong,

bye..


JariTapio / Helsinki

//--------

Game developing is a way of fun..
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2006-12-02 23:28:25 »

Although Kova was a bit rude, he's quite right.

When trivial errors like this are a showstopper for you, it won't help when we give you the solution, you'd - unfortunately - bump right into the next trivial error.

Get yourself a nice Java book, and believe me, there are only a few really good ones. Try one that doesn't mention AWT/Swing at all, because it will only get in the way when learning the basics (i'm dead-serious about this). Command-line applications is the way to go. Once you know all about Java, it's time to build some GUIs.

Goodluck!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Kova

Senior Devvie





« Reply #6 - Posted 2006-12-03 03:42:43 »

I was a bit rude, but I think I had right to be rude in this instance. At the end I told you what the problem is. If it's about File I/O or something like that I would reply nicely, but you don't know how to use methodes (functions), and that's basics of basics, not just for java but for all programming. Second, java compiler told you exactly what is wrong, but you don't know how to read errors also. So although you have some experience in programming (didn't try your game) you have not enough experience in java to code ... well... pretty much anything. I'm not trying to be rude here, just speaking the truth as I see it.

What helped me the most when I was starting out with java is free e-book: Thinking in Java by Bruce Eckel. I had 3rd edition and it is free, but I think 4th edition isn't free anymore. Thinkin in java is for begginers in java that have basic programming experience. Try  www.bruceeckel.com, maybe you can still download 3rd edition for free.
EDIT: ...3rd edition is still there, here is direct link to zip file
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Reply #7 - Posted 2006-12-03 13:57:35 »

Hei!  Smiley

My first post was a bit miss leading, sorry for that, as im not that beginner what it lets people to understand, sorry,  i just havent made IO routines with Java, ever.

i can build many different types of games with c++ and some with Java, but, liked i said, i havent made Java IO routines, ever, and would really presiate if
someone could help me a bit..

the problem is that i dont know how to read a data file from a path where .CLASS files are..
in c++ if you want to load a file from a directory where .exe file is launched you simply use "thefilename.dat" and nothing else this seems not to be true with java Huh
if i put a line to my code..
            in = new FileInputStream ("input.txt");
i receive an error even if my 'input.txt' is on my .CLASS directory, why..  Lips Sealed


public void copyBytes () throws IOException
{   
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream ("c:/input.txt");
            out = new FileOutputStream("c:/output.txt");
            int c;

            while ((c = in.read()) != -1) {
                out.write(c);
            }

        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
}

code works fine but when i change the line
            in = new FileInputStream ("c:/input.txt");
to
            in = new FileInputStream ("input.txt");
to load file 'input.txt' from where the .class files are, i receive an 'file not found', why Huh
from where is Java loading 'input.txt' when there is no path included?? c++ loads where the .exe is  Huh

java.io.FileNotFoundException: input.txt (The system cannot find the file specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at MultiBufferTest.copyBytes(MultiBufferTest.java:84)
        at MultiBufferTest.<init>(MultiBufferTest.java:106)
        at MultiBufferTest.main(MultiBufferTest.java:184)

JariTapio / Helsinki

//---

Game developing is a way of fun, thanks for your code..
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2006-12-03 15:41:58 »

The file is relative to the working-directory.

If you have a class Abc in package xyz.qrs, that would be invoked like:

Say you have your classes at:
C:\java\classes

make that your current-directory (cmd.exe -> cd)
then call:
java xyz.sqr.Abc

Now new File("input.txt") will be relative to your working-dir, being:
C:\java\classes\input.txt


However, if you have another current-directory, like:
cd D:
java -classpath C:\java\classes xyz.qrs.Abc

now the file "D:\input.txt" would be searched for.


Well... this is exactly the same in C/C++ with EXE-files... your working-directory just happened to be the same as the directory that contained the EXE

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline NewOnJava

Junior Devvie




1970 born Java game hobbyer.


« Reply #9 - Posted 2006-12-03 16:53:29 »

Hei!   Cool 

thanks Riven, i now get my "input.txt" file to be loaded from the same directory where my executable jar file is launched..  Grin  Grin  Grin

my new questions are -
    how to modify the code to make the "input.txt" file to be loaded inside the jar  Tongue
    secondly is it possible to write a file "output.txt" to a jar  Tongue
    and finally, if im using NetBeans IDE 5.5 how to modify the code to make my application
    run without errors from IDE when "input.txt" is located at '/build/classes/' directory ?? Huh

i need somekind of a classPath (); function   Cool

public void copyBytes () throws IOException
{   
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream ("input.txt");
            out = new FileOutputStream("output.txt");
            int c;

            while ((c = in.read()) != -1) {
                out.write(c);
            }

        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
}

JariTapio / Helsinki

//----

Game developing is a way of fun, thanks for your code..
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pepijnve

Junior Devvie




Java games rock!


« Reply #10 - Posted 2006-12-05 10:22:13 »

You can access files that are located in the classpath using a ClassLoader. More specifically you can use the methods ClassLoader#getSystemResourceAsStream or ClassLoader#getResourceAsStream.
As far as I know j2se doesn't provide any API to update an existing jar file. It's pretty straightforward to create a new one though using a JarOutputStream.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!