3

can someone help me? i'm pretty new to programming, I decided to give IDEA a try comming from eclipse and I have run into a problem I have imported a project from eclipse that works but in IDEA I cant referance my res folder like I do in eclipse like I cant use res/image.png I can only do c:\ect. anyone know why? I have set the res folder as a resource root.

Syntaxis
  • 69
  • 1
  • 1
  • 8
  • and I have just figured it out i need to add the project to the path aswell so instead of just res/image.png I need to use myproject/res/image.png, it works but I like using just res/image.png as thats what im used to is there any way arround that? – Syntaxis Jan 16 '15 at 13:00
  • if you're coding for android just use Android Studio. there is a wizard for importing eclipse projects and it worked well for me. – eriuzo Jan 16 '15 at 13:11
  • no its not for android its a regular java program, sorry about the android tag that was a accident. – Syntaxis Jan 16 '15 at 14:19
  • Heya, if you put the images in a source root, compile, and access them via "classloader" `getResourceAsStream(...)`, this might be a way to solve your problem – vikingsteve Jan 17 '15 at 09:48
  • no that didn't work, ok so this is my projects hierarchy: first is `(to my classes)myProject> src/main/java(the source root)/com.glen.game` then (to my resources) `myProject>src/main/res(the source root)` then in my code I have to use `texture = TextureLoader.getTexture("PNG", new FileInputStream("myproject/src/main/res/" + fileName+ ".PNG"));` and in eclipse i normaly use `texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + fileName+ ".PNG"));` and that works in eclipse but not IDEA – Syntaxis Jan 17 '15 at 10:48

2 Answers2

6

For a project structure like this:

project
|
| -> src
|    |
|    | -> directory
|    |    |
|    |    | -> MyClass.java
|    |    |
|    |    | -> file.txt

Use the below code to read the file in MyClass.java

import java.io.*;

class MyClass {

    public static void main(String... args) {

        try {

            BufferedReader br = new BufferedReader(new FileReader("src/directory/file.txt"));

            // read your file 

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}
Ashwin
  • 7,277
  • 1
  • 48
  • 70
0
  1. Right-click on the project
  2. Click new
  3. Click resource Bundle
  4. Select the Resource name

And you are good to go. Put your files here.

RiveN
  • 2,595
  • 11
  • 13
  • 26