• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access remote files

 
Santosh Kumar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print the exception stack trace. It will help us in trouble shooting.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the I/O forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic