• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

how to access remote files  RSS feed

 
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;
}
}
 
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.
 
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.
 
Author and ninkuma
Marshal
Posts: 66806
168
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!