Click here to Skip to main content
15,900,725 members
Home / Discussions / Java
   

Java

 
AnswerRe: Adding command line arguments to batch file produced from Ant build script Pin
Tarakeshwar Reddy25-Apr-11 12:23
professionalTarakeshwar Reddy25-Apr-11 12:23 
Questionplease help me Pin
Mohammed Kherfan24-Apr-11 8:09
Mohammed Kherfan24-Apr-11 8:09 
AnswerRe: please help me Pin
_Erik_25-Apr-11 3:16
_Erik_25-Apr-11 3:16 
AnswerRe: please help me Pin
Richard MacCutchan25-Apr-11 5:04
mveRichard MacCutchan25-Apr-11 5:04 
GeneralRe: please help me Pin
scottgp25-Apr-11 8:31
professionalscottgp25-Apr-11 8:31 
GeneralRe: please help me Pin
Richard MacCutchan25-Apr-11 21:43
mveRichard MacCutchan25-Apr-11 21:43 
AnswerRe: please help me Pin
TorstenH.25-Apr-11 12:01
TorstenH.25-Apr-11 12:01 
QuestionWhat is the problem accessing "C" drive using a code (using import.io.*; )? Pin
CoderForEver23-Apr-11 20:36
CoderForEver23-Apr-11 20:36 
Hi guys,

The aim of this code is to find a file by giving starting folder. The problem is, when I use "C:\\" directory it doesn't work, even I tried "C:" and "C" if it was the problem. I think the problem is related to some Access restriction. If I changed the starting folder, lets say, to "C:\\someFolder" it will work perfectly.

How can I make the code work so that it will start searching from C drive .. Help me Thank you

package ex4;

import java.io.*;

public class FileSearchRecursive {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		FileSearchRecursive x=new FileSearchRecursive();
                if(!(x.searchForFile("C:\\","try.txt")))//works find if I changed the statement to 
                                                        if(!(x.searchForFile("C:\\someFolder","try.txt")))
			System.out.println("File not found");

	}	
		
	boolean searchForFile(String startDir,String fileName)
	{		
				
		File file1=new File(startDir);
		
		if(file1.exists())
		{
		File[] list=file1.listFiles();
			for(File x: list)
			{
					
				 if(x.isFile())
				{					
					if(x.getName().equals(fileName))	
					{
						System.out.println("I got the file "+x.getName()+" in "+x.getAbsolutePath());
						return true;
					}
				}
				 else if(x.isDirectory())
					{
						if(searchForFile(x.getAbsolutePath(),fileName))
							return true;
					}		
				
			}
		}			
		
		
		return false;
	}


}

AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
jschell25-Apr-11 8:21
jschell25-Apr-11 8:21 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
CoderForEver25-Apr-11 12:07
CoderForEver25-Apr-11 12:07 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
TorstenH.25-Apr-11 19:33
TorstenH.25-Apr-11 19:33 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
jschell26-Apr-11 8:00
jschell26-Apr-11 8:00 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
jschell26-Apr-11 7:57
jschell26-Apr-11 7:57 
AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Richard MacCutchan25-Apr-11 22:16
mveRichard MacCutchan25-Apr-11 22:16 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Nagy Vilmos27-Apr-11 5:43
professionalNagy Vilmos27-Apr-11 5:43 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Richard MacCutchan27-Apr-11 6:53
mveRichard MacCutchan27-Apr-11 6:53 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
David Skelly28-Apr-11 1:48
David Skelly28-Apr-11 1:48 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Richard MacCutchan28-Apr-11 5:54
mveRichard MacCutchan28-Apr-11 5:54 
AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
CoderForEver26-Apr-11 3:26
CoderForEver26-Apr-11 3:26 
GeneralRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Richard MacCutchan26-Apr-11 10:15
mveRichard MacCutchan26-Apr-11 10:15 
AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Luc Pattyn26-Apr-11 4:05
sitebuilderLuc Pattyn26-Apr-11 4:05 
AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
jschell26-Apr-11 8:03
jschell26-Apr-11 8:03 
AnswerRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
David Skelly26-Apr-11 22:16
David Skelly26-Apr-11 22:16 
RantRe: What is the problem accessing "C" drive using a code (using import.io.*; )? Pin
Richard MacCutchan26-Apr-11 22:28
mveRichard MacCutchan26-Apr-11 22:28 
QuestionIf string is a immutable class then how come it is allowing us to make changes ? Pin
shiva.kore23-Apr-11 7:11
shiva.kore23-Apr-11 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.