File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes how to access remote files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to access remote files" Watch "how to access remote files" New topic
Author

how to access remote files

Santosh Kumar
Ranch Hand

Joined: May 25, 2005
Posts: 30
hi

i am able to access the remote system files using the java code as follows

java file
----------

import java.io.*;
import java.lang.String;
import java.io.File;
import java.util.*;
import java.util.List;
import java.lang.*;

public class FilecheckTest
{
public static void main(String args[])
{
File file_mem = new File("\\\\machinename
\\folder1\\folder2\\folder3\\folder4\\");

Map mapfiles = new HashMap();
showFiles(file_mem, mapfiles);
Iterator iterator_mapfiles = mapfiles.keySet().iterator();
while(iterator_mapfiles.hasNext())
{
String fpath= (String)iterator_mapfiles.next();
String fname= (String)mapfiles.get(fpath);
System.out.println(fname);
System.out.println(fpath);
}
}


but when i convert into a jsp file i am getting a Nullpointer error
the jsp code is as follows
----------------
<%@ page language="java" import="java.io.*,java.lang.String,java.io.File,java.util.*,java.util.List,java.lang.*" %>

<%!
//getting file name and url
Map mapfiles = new HashMap();
Map showFiles(File file)
{
File[] files = file.listFiles();
if(file.isDirectory())
{
for(int i=0;i<files.length; i++)
{
showFiles(files[i]);
}
}
else
{
String path = file.getPath();
String name = file.getName();
mapfiles.put(path,name);
}
return mapfiles;
}
%>

<%

File file_mem = new File("\\\\machinename
\\folder1\\folder2\\folder3\\folder4\\");
Map map = showFiles(file_mem);
Iterator iterator_mapfiles = map.keySet().iterator();
while(iterator_mapfiles.hasNext())
{
String fpath= (String)iterator_mapfiles.next();
String fname= (String)map.get(fpath);

out.println(fname);
out.println(fpath);
}


%>

//getting file name and url
public static Map showFiles(File file, Map mapfiles)
{
File[] files = file.listFiles();
if(file.isDirectory())
{
for(int i=0;i<files.length; i++)
{
showFiles(files[i], mapfiles);
}
}
else
{
String path = file.getPath();
String name = file.getName();
mapfiles.put(path,name);
}
return mapfiles;
}
}
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Javaranch Tip:

Wrapping your code in UBB CODE Tags will preserve your indenting and greatly increase the likelyhood that someone will actually read your post.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Print the exception stack trace. It will help us in trouble shooting.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Moved to the I/O forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access remote files