List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage original = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR); BufferedImage copy = original.getSubimage(10, 10, 50, 50); ImageIO.write(copy, "png", new File("Test.png")); }
From source file:MainClass.java
License:asdf
public static void main(String[] args) throws Exception { String characterName = "asdf"; SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new File("r.xml")); List actList = document.getRootElement().getChildren("ACT"); allDone: for (int act = 0; act < actList.size(); act++) { List sceneList = ((Element) actList.get(act)).getChildren("SCENE"); for (int scene = 0; scene < sceneList.size(); scene++) { List speechList = ((Element) sceneList.get(scene)).getChildren("SPEECH"); for (int speech = 0; speech < speechList.size(); speech++) { if (characterName .equalsIgnoreCase(((Element) speechList.get(speech)).getChildText("SPEAKER"))) { System.out.println(characterName); break allDone; }//from w w w .j a v a2 s . co m } } } }
From source file:TrySAXHandler.java
public static void main(String args[]) throws Exception { File file = new File("y.xml"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = null;//from ww w . j a va 2s . co m spf.setNamespaceAware(true); spf.setValidating(true); System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ") + "be namespace aware"); System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML"); parser = spf.newSAXParser(); System.out.println("Parser object is: " + parser); MySAXHandler handler = new MySAXHandler(); parser.parse(file, handler); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("image.gif"); System.out.println(getFormatName(file)); InputStream is = new FileInputStream(file); is.close();//w ww . j a v a 2s. com System.out.println(getFormatName(is)); }
From source file:Converter.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream(new File("input.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(fis, "SJIS")); FileOutputStream fos = new FileOutputStream(new File("output.txt")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos, "UTF8")); int len = 80; char buf[] = new char[len]; int numRead;//from w w w.j av a 2 s . com while ((numRead = in.read(buf, 0, len)) != -1) out.write(buf, 0, numRead); out.close(); in.close(); }
From source file:Main.java
public static void main(String argv[]) throws Exception { File fXmlFile = new File("data.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("staff"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); System.out.println("\nCurrent Element :" + nNode.getNodeName()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; System.out.println("Staff id : " + eElement.getAttribute("id")); System.out.println(/*from w w w . j a v a 2s . c o m*/ "First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent()); System.out.println( "Last Name : " + eElement.getElementsByTagName("lastname").item(0).getTextContent()); System.out.println( "Nick Name : " + eElement.getElementsByTagName("nickname").item(0).getTextContent()); System.out.println("Salary : " + eElement.getElementsByTagName("salary").item(0).getTextContent()); } } }
From source file:Main.java
public static void main(String[] args) { // create a new list of arguments for our process String[] list = { "notepad.exe", "test.txt" }; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // set the working directory of the process pb.directory(new File("C:/")); System.out.println(pb.directory()); }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w. j a v a 2 s . c om*/ char[] chars = new char[2]; chars[0] = '\u4F60'; chars[1] = '\u597D'; String encoding = "GB18030"; File textFile = new File("C:\\temp\\myFile.txt"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(textFile), encoding); writer.write(chars); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:Main.java
public static void main(String[] args) { // create a new list of arguments for our process String[] list = { "notepad.exe", "test.txt" }; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); try {//ww w.ja v a 2s . c om pb = pb.redirectError(new File("c:/")); pb.start(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // create a new list of arguments for our process String[] list = { "notepad.exe", "test.txt" }; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); try {/* w w w. j a v a2 s .com*/ pb = pb.redirectInput(new File("c:/")); pb.start(); } catch (IOException ex) { ex.printStackTrace(); } }