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