Java uses a dialog box to select a file and output it to the console

Source: Internet
Author: User

ImportJava.util.*;ImportJava.io.*;ImportJavax.swing.JFileChooser; Public classReadfileusingjfilechooser {/**     * @paramargs *@throwsException*/     Public Static voidMain (string[] args)throwsException {//TODO auto-generated Method StubJFileChooser jfc=NewJFileChooser (); if(Jfc.showopendialog (NULL)==jfilechooser.approve_option) {File File=Jfc.getselectedfile (); Scanner input=NewScanner (file);  while(Input.hasnext ()) {System.out.println (Input.nextline ());        } input.close (); }        ElseSystem.out.println ("No file is selected!"); }}

Summarize:

1. The string object is immutable and its contents cannot be changed. To improve efficiency and save memory, if two direct-weight strings have the same sequence of characters, the JVM stores them in an object.

2. You can call the length () method of string to get its lengths, use the Charat (index) method to raise a character in a specific subscript position from a string, and use the IndexOf and LastIndexOf methods to find a character or a substring of a string.

3, you can use the Concat method to connect two strings, or use the Plus +.

4. The Stringbuilder/stringbuffer class can be used instead of the string class. The string class is immutable, but you can add, insert, or append new content to the Stringbuilder/stringbuffer object.

Java uses a dialog box to select a file and output it to the console

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.