Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:12:21+00:00 2026-06-01T06:12:21+00:00

This is my first time working with file i/o in java, and it’s not

  • 0

This is my first time working with file i/o in java, and it’s not working. The section of the program where I parse individual lines and output a semicolon delimited line works like a charm when I hardcode a file and display on screen.

Whne I try to write to a file public static OutputStream... errors out as an illegal start to expression, and I’ve been unable to get the program to step through an entire directory of files instead of one at a time.

Where I’m not clear: I’m note setting an output filename anywhere…whare am I supposed to do that? The path variable won’t pass. What’s the proper format for a path? Can anyone see what I need to debug here?

import java.nio.*;
public class FileReadSSCCE
{
    public static void main(String args[])
    {
        try
        {
     Path startingDir = Paths.get("R:\Data\cs\RoboHelp\CorrLib\Output\Production\WebHelp");
      PrintFiles pf = new PrintFiles();
      Files.walkFileTree(startingDir, pf);
  // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
              BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String inputLine;
            String desc = "";
            String docNo = "";
  //Read File Line By Line
        while ((inputLine = br.readLine()) != null)
            {
                int testVal=0;
                int stringMax = inputLine.length();
//
                if(inputLine.startsWith("Description"))
                  {desc = inputLine.substring(13,inputLine.length());}
                   else
                   if(inputLine.startsWith("Reference Number"))
                     {docNo = inputLine.substring(20,inputLine.length());}    
            }    
// Print the content on the console
            String outStr1 = (desc + ";" + docNo);
            System.out.print(inputLine + "\n" + outStr1);
            String lineItem = (outStr1);
//    
            try (OutputStream out = new BufferedOutputStream
                 (logfile.newOutputStream(CREATE, APPEND)))
                 {
                     out.write(lineItem, 0, lineItem.length);
                 }
                 catch (IOException x)
                 {
                     System.err.println(x);
                 }
                 public static OutputStream newOutputStream() throws IOException
                 {
                       // append to an existing file, create file if it doesn't initially exist
                       out = Files.newOutputStream((Paths.get("c:\javaout.txt"), CREATE, APPEND);
                 }

//Close the input stream
            in.close();
       } 
       catch (Exception e)
       {
           //Catch exception if any
           System.err.println("Error: " + e.getMessage());
       }

   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:12:23+00:00Added an answer on June 1, 2026 at 6:12 am

    Do you mean:

    Path startingDir = Paths.get("R:/Data/cs/RoboHelp/CorrLib/Output/Production/WebHelp");
    

    ?

    Also in your code, fstream is not initialised. Have you copied your code logic in the visitFile method of your Visitor?

    And you define a method within your main method – which is not allowed:

            public static OutputStream newOutputStream() throws IOException
            {  
                // append to an existing file, create file if it doesn't initially exist  
                out = Files.newOutputStream(c:, CREATE, APPEND);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time working with Objective-C, and I keep trying to create
This is just the first time I'm working on Adobe Flash CS5. I have
This is the first time I am working with struts (1.2) In my jsp
Working with images in Java for the first time and am getting some bizarro
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time using joomla. I don't know if I'm using the
This is my first time with Web services. I have to develop web services
this is my first time posting here, I have a question which I have
This is my first time on StackOverflow though I read Coding Horror quite often.
This is the first time I'm creating an open-source project, and I've decided (based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.