#i cant get the file with the file path

1 messages · Page 1 of 1 (latest)

winged stirrup
#

i was trying to read a text file in the resources file(i was using maven) but it wont work with relative path, im using filereader

cloud yewBOT
#

This post has been reserved for your question.

Hey @winged stirrup! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

swift creekBOT
#

the code:


public class FileUtils {
   public static String readAsString(String filePath) {
       StringBuilder result = new StringBuilder();
       
       try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
           String line;
           while ((line = reader.readLine()) != null) {
               result.append(line).append('\n');
           }
       } catch (IOException e) {
           e.printStackTrace(); // Handle exceptions appropriately
       }
       return result.toString();
   }
   public static Object[] readEachLine(String filePath) {
       ArrayList<String> result = new ArrayList<String>();
       try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
           String line;
           while ((line = reader.readLine()) != null) {
               result.add(line);
           }
       } catch (IOException e) {
           e.printStackTrace();
       }
       return result.toArray();
   }
} ```

This message has been formatted automatically. You can disable this using /preferences.

winged stirrup
#

work❤️ :

FileUtils.readAsString("D:\\Bao\\eclipse-Workspace\\103GE-CORE\\src\\main\\resources\\shaders\\FragmentShader.fs") 

hell nah💔:

FileUtils.readAsString("\\src\\main\\resources\\shaders\\FragmentShader.fs")
magic fossil
#

Resources are not files

#

you can use getClass().getClassLoader().getResource("shaders/FragmentShader.fs") or similar

#

accessing resources as files does not work when the application is packaged (e.g. in a JAR file)

cloud yewBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

winged stirrup
cloud yewBOT
# winged stirrup thank you it work

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

winged stirrup
#

❤️