0

Hi,

I am writing a code that will get a file in the linux server(server.logs). Can anyone help me out with that. I am using a java se in a windows. and i dont knw how to retireve file on it. I need to log the files and parse the details of it. It is a continuous file since the file that i read is a server logs.

3
Contributors
11
Replies
12
Views
8 Years
Discussion Span
Last Post by Truffy
0

Please read the Methods of class File. The class File is file system independent class.

what do you mean by that?

0

Please read the Methods of class File. The class **File **is file system independent class.[/QUOTE]
what do you mean by that?

this is the problem that i encounter:

java.io.FileNotFoundException: \\10.123.45.67\apps\user\staging\aa\log\success.* (The network path was not found)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at java.io.FileReader.<init>(FileReader.java:55)
    at events.TestJava.main(TestJava.java:31)
Exception in thread "main" java.lang.NullPointerException
    at events.TestJava.main(TestJava.java:64)
Java Result: 1

my code is this:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class TestJava {
    public static void main(String args[]) {
        File file = null;
        FileReader fr = null;
        BufferedReader in = null;
//      String userHome = System.getProperty("user.home");
//      String fileSeparator = System.getProperty("file.separator");

        try {
                       file = new File("\\10.123.45.67\apps\user\staging\aa\log\success.*");

//          file = new File("c:\\success.log");
            fr = new FileReader(file);
            in = new BufferedReader(fr);

            String request = null;
            String requestIP = null;
            String message = null;

            String temp = null;
            temp = in.readLine();   

            if (temp.equals("========================= INCOMING MESSAGE =========================")) {
                temp = in.readLine();
                String[] text = temp.split("\\|");
                request = text[0];
                requestIP = text[1];
                message = text[2];
            }
//                        if (temp.equals("========================= INCOMING MESSAGE =========================")) {
//              temp = in.readLine();
//              String[] text = temp.split("\\|");
//              request = text[0];
//              requestIP = text[1];
//              message = text[2];
//          }

            System.out.println(request + " = " + requestIP);
            System.out.println(message);
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
}

Edited by Reverend Jim: Fixed formatting

0

Wrong way you select for a path.

file = new File("\\10.123.45.67\\apps\\user\\staging\\aa\\log\\success");
0

Wrong way you select for a path.

file = new File("\\10.123.45.67\\apps\\user\\staging\\aa\\log\\success");

i hanged it then this is the error.
this is the error:
java.io.FileNotFoundException: \10.123.45.67\apps\user\aa\log\success(The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at events.TestJava.main(TestJava.java:31)
Exception in thread "main" java.lang.NullPointerException
at events.TestJava.main(TestJava.java:64)
Java Result: 1

0

i hanged it then this is the error.
this is the error:
java.io.FileNotFoundException: \10.123.45.67\apps\user\aa\log\success(The system cannot find the path specified)

Please check whether a file named "success" is available or not.

0

Please check whether a file named "success" is available or not.

yeah it has a correct file name. my file is from the open-ssh.

0

it just a matter of escape character '\' in windows,
you need to type '\\' for single backslash '\', and for double backslash you'll need '\\\\', so instead of

file = new File("\\10.123.45.67\apps\user\staging\aa\log\success.*");

you must use:

file = new File("\\\\10.123.45.67\\apps\\user\\staging\\aa\\log\\success.log");

don't use success.* cause Java will not understand that, you must specify full name with its extension.

CMIIW,

0

Please check whether a file named "success" is available or not.

it just a matter of escape character '\' in windows,
you need to type '\\' for single backslash '\', and for double backslash you'll need '\\\\', so instead of

file = new File("\\10.123.45.67\apps\user\staging\aa\log\success.*");

you must use:

file = new File("\\\\10.123.45.67\\apps\\user\\staging\\aa\\log\\success.log");

don't use success.* cause Java will not understand that, you must specify full name with its extension.

CMIIW,

still the same error: network does not found.

0

Oh, i see ..
I think you can't access file in linux from windows just using java.io.File cause it is in another layer (network).

try open the path:

\\10.123.45.67\apps\user\staging\aa\log\success.log

using Windows Explorer, i guess it will cause same error:
"network does not found"

unless you're accessing samba path for your linux file, it can't be accessed by your code.

0

Oh, i see ..
I think you can't access file in linux from windows just using java.io.File cause it is in another layer (network).

try open the path:

\\10.123.45.67\apps\user\staging\aa\log\success.log

using Windows Explorer, i guess it will cause same error:
"network does not found"

unless you're accessing samba path for your linux file, it can't be accessed by your code.

yes, i cant access it through run cmd line. hmmm,, what do you think will i do to this problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.