Sunday, September 16, 2012

Create Virtual drive using Dos command

SUBST


Syntax

Associates a path with a drive letter.


SUBST [drive1: [drive2:]path]

SUBST drive1: /D

drive1: Specifies a virtual drive you want to assign a path.

[drive2:]path Specifies a physical drive and path you want to assign to a virtual drive.

/D Deletes a substituted (virtual) drive.


Type SUBST with no parameters to display a list of current virtual drives.



Examples


C:/>SUBST z: C:/porject/rms

C:/> SUBST z: /D      (Deletes the virtual drive.)

Sets the directory you are in and subdirectories thereafter into the A: drive. So if you were to type A: after doing this command you would see everything in the directory that you typed this command in.

If you were to reboot your computer this will clear the SUBST command and put your drives back to original letters (unless command placed into the autoexec.bat).



Find String in Files using Dos command

FINDSTR
Search for strings in files.



Syntax

FINDSTR [options] [/F:file] [/C:string] [/G:file]

[/D:DirList] [/A:color] [/OFF[LINE]] [string(s)] [pathname(s)]



FINDSTR [options] [/F:file] [/R] [/G:file]

[/D:DirList] [/A:color] [/OFF[LINE]] [string(s)] [pathname(s)]

Key

string Text to search for.

pathname(s) The file(s) to search.

/C:string Use string as a literal search string.

/R Use string as a regular expression.

/G:file Get search string from a file (/ stands for console).

/F:file Get a list of pathname(s) from a file (/ stands for console).

/A:color Display filenames in colour (2 hex digits)

/d:dirlist Search a comma-delimited list of directories.



options may be any combination of the following switches:

/I Case-insensitive search.

/S Search subfolders.

/P Skip any file that contains non-printable characters

/OFF[LINE] Do not skip files with the OffLine attribute set.

/L Use search string(s) literally.

/B Match pattern if at the Beginning of a line.

/E Match pattern if at the END of a line.

/X Print lines that match exactly.

/V Print only lines that do NOT contain a match. /N Print the line number before each line that matches.

/M Print only the filename if a file contains a match.

/O Print character offset before each matching line.


Example:

C:/Docs/test> findstr /I /S /P /M "Venkata Naresh" *

Explanation:

Search "Venkata Naresh" in all the files in folder "C:/Docs/test".




Monday, July 16, 2012

Read XML File Using Java

1) Save Xml file name :bookstore.xml in C dirve

<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title >Harry Ptter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

2) Read above bookstore.xml using java code. BookStore.java


import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


/**
 *
 */

/**
 * @author Administrator
 *
 */
public class BookStore {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub


try {
File bookXml = new File("C:\\bookstore.xml");

DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuildFactory.newDocumentBuilder();
Document doc = docBuilder.parse(bookXml);
doc.getDocumentElement().normalize();

System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName("book");
System.out.println("-----------------------\n");

for (int temp = 0; temp < nodeList.getLength(); temp++) {

  Node nodeNode = nodeList.item(temp);
  if (nodeNode.getNodeType() == Node.ELEMENT_NODE) {

     Element eElement = (Element) nodeNode;

     System.out.println("Title : " + getTagValue("title", eElement));
     System.out.println("Author : " + getTagValue("author", eElement));
         System.out.println("Year : " + getTagValue("year", eElement));
     System.out.println("Price : " + getTagValue("price", eElement));
     System.out.println("\n\n");
  }
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
private static String getTagValue(String strTag, Element eElement) {
NodeList nodeList = eElement.getElementsByTagName(strTag).item(0).getChildNodes();

   Node nodeValue = (Node) nodeList.item(0);

return nodeValue.getNodeValue();
 }
}


Below is the out put:

Root element :bookstore
-----------------------

Title : Everyday Italian
Author : Giada De Laurentiis
Year : 2005
Price : 30.00



Title : Harry Ptter
Author : J K. Rowling
Year : 2005
Price : 29.99



Title : Learning XML
Author : Erik T. Ray
Year : 2003
Price : 39.95



Everyday Italian