#File not generating when running the program

1 messages ยท Page 1 of 1 (latest)

crystal sand
#

hey so i'm having trouble with trying to generate a txt file for an assignment. It's supposed to generate two files the first one is a .dat file and that one gets created perfectly fine. However the other one which is a .txt file is not here is the code i have

private static final String LOGFILE = "reminderlog.txt";

and then i also have

    public void log(Reminder r) {
        LocalDateTime local = LocalDateTime.from(
                Instant.now().atZone(ZoneId.systemDefault()));
        String msg = local.truncatedTo(ChronoUnit.MILLIS) +
                ":Reminder:" + r.getContact().getName();
        System.out.println("Log File Path = " + Path.of(LOGFILE).toAbsolutePath()); // tells us the directory path.
        try (BufferedWriter reminderlog = Files.newBufferedWriter(Path.of(LOGFILE),
                StandardOpenOption.CREATE, StandardOpenOption.APPEND);) {
            reminderlog.write(msg);
            reminderlog.newLine();
            reminderlog.close(); // Close the BufferedWriter
        } catch (IOException e) {
            System.err.println("LOG FAIL" + msg);
            e.printStackTrace();
        }
    }```

idk if this code will be enough for someone to help me out but if you want me to send the full source code i can.
thorny ospreyBOT
#

<@&987246399047479336> please have a look, thanks.

thorny ospreyBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

ne is a .txt file. However, when I run the program, only the .dat file is being generated and the .txt file is missing. I'm not sure what's causing this issue. Can you help me troubleshoot?

Sure, I'd be happy to help you troubleshoot the issue. Here are a few steps you can follow to identify and resolve the problem:

  1. Check your code: Double-check your code to ensure that you have included the necessary instructions for generating both files. Make sure that you have specified the correct file extension (.txt) for the text file.

  2. Verify file paths: Ensure that you are providing valid and accessible file paths for both files. Check if the directory where you expect the text file to be generated exists and that your program has permission to write files in that location.

  3. Error handling: Implement proper error handling in your code to catch any potential exceptions or errors that might occur during file generation. This will help you identify any issues with creating or writing to the text file.

#
  1. Debugging output: Add some debugging output statements in your code to print relevant information during runtime, such as the paths being used for file generation or any error messages encountered.

  2. Test with different data: Try generating the files with different input data or test cases to see if it consistently fails or if it's specific to certain inputs.

  3. Run as administrator: If you're working on a Windows system, try running your program as an administrator to ensure it has sufficient permissions for creating files.

  4. Check disk space: Verify that there is enough free disk space available on your system drive or the drive where you expect the files to be generated.

  5. Test on a different machine: If possible, try running your program on a different machine or environment to see if it produces both files correctly there. This can help determine if there are any system-specific issues causing this problem.

By following these steps, you should be able to identify the cause of the issue and resolve it. If you're still facing difficulties, please provide more details about your code or any error messages you're encountering, and I'll be glad to assist you further.

crystal sand
#

Hello

warm turtle
crystal sand
#

Alright I'll see if that's the issue

#

I'm not at my PC atm

warm turtle
hollow drift
crystal sand
crystal sand
warm turtle
# crystal sand tried that did nothing

something prolly wrong before you create the file then, also try-with-resources auto closes resources, so no need for writer.close() when you're done writing.

warm turtle
hollow drift
crystal sand
#

yeah it runs

ionic estuary
#

hes asking what it prints, like is the path in order and are all the prints from the method there

crystal sand
#

well first it prints the directory where the files are supposed to be stored

#

and then it runs like usual

crystal sand
#

i can post the full source code if needed

thorny ospreyBOT
crystal sand
#

wait i think i got something

#

holy crap

#

i got it to work

#

i just forgot one line of code

crystal sand
#

does that ever happen to anyone?