0

I'm writing a java code to go through a .sfo (a combination of SQL and Fortran) file and remove a certain set of characters whenever they show up in the file. I'm using Eclipse on a 64-bit Windows 7 machine, if that makes any difference. The code is doing what I want, removing the blocks of characters and whatnot, but at the end, after it gives me my output, it shows "Error: No such file or directory." I don't know why; the only external file that I am referencing is the aforementioned .sfo. The file exists, and the file path that I specified in the code is correct. I have permissions to read and write to the file. Here is my code (more or less; a lot of it is repetitive, so I'll cut out some of the unimportant stuff):

The absolute path is

C:/Users/frencke/p4/frencke_LOHEPCE00294173/pcs/main/lib/gp/file.sfo.

Yes, I have full permissions on the file.

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class StringSplit {
    public static void main(String args[]) {
        try {
            ArrayList<String> arr = new ArrayList<String>();
            // Here I initialized a bunch of ArrayLists; nothing relevant
            ArrayList<String> arr26 = new ArrayList<String>();
            FileInputStream fstream = new FileInputStream(
                    "C:/Users/.../file.sfo");
            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                arr.add(strLine);
                String[] temp;
                String delimiter = "\\s+\\s+\\s+\\s+\\s+&\\s+";
                temp = strLine.split(delimiter);
                for (int i = 0; i < temp.length; i++)
                    arr2.add(temp[i]);
                // Here I did all of the removal of the various blocks of text
                String[] temp27;
                String delimiter27 = "\t9";
                String strLine27 = null;
                for (int i = 0; i < temp26.length; i++)
                    strLine27 = temp26[i];
                temp27 = strLine27.split(delimiter27);
                for (int i = 0; i < temp27.length; i++)
                    System.out.println(temp27[i]);
                in.close();
            }
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}

Again, the error message I got was: "Error: No such file or directory." If anyone knows why this is happening, I would love to hear it; thanks!

11
  • What is the absolute path of file.sfo? Commented Jul 3, 2013 at 18:23
  • Does the file has the read permission ? Commented Jul 3, 2013 at 18:27
  • Sorry if I was unclear; the "..." was just showing where I cut out a big part of the file path for reading purposes on this website. The absolute path is there in full in the code (it's C:/Users/frencke/p4/frencke_LOHEPCE00294173/pcs/main/lib/gp/file.sfo.) Yes, I have full permissions on the file. Commented Jul 3, 2013 at 18:31
  • @ItsanAlias I edit the commented information. Please make edit in OP next time and why delimiter = "\\s+\\s+\\s+\\s+\\s+&\\s+";? Commented Jul 3, 2013 at 18:34
  • 1
    @ItsanAlias You are closing the DataInputStream in your while loop. Anyhow you can still use \\s+ will encounter one or more whitespace. Commented Jul 3, 2013 at 18:40

3 Answers 3

1

You are closing the InputStream at the end of the first iteration of your while loop - this releases any system resources associated with the stream.

When you try to readLine(), the stream has already been released so that's why it says No such file exists.

I think you meant to put the in.close() after the loop, that should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that was the problem. I changed that and it works fine now. Thanks!
0

Try to give file path like this "C:\\Users\\...\\file.sfo"

Comments

0

Just remove "/" character with File.separator. Example:

String path = "C:/Users/.../file.sfo";
path = path.replaceAll("//",File.separator);
FileInputStream fstream = new FileInputStream(path);

1 Comment

That doesn't seem to help; I think that Smit has it figured out. Something about where I close my DataInputStream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.