编写一个java程序, 可以读取java文件,并读取出所有内容,并自动对{和}涉及到的空格进行自动修改。
Whenyouseea{leftbracecharacterinthefile,increaseyourindentationlevelbyfourspaces.When...
When you see a { left brace character in the file, increase your indentation level by four spaces. When you see a } right brace character, decrease your indentation level by four spaces.
展开
1个回答
展开全部
import java.io.File;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("行数: " + getLineCountOfFile("c:\\1.txt"));
}
public static int getLineCountOfFile(String filePath) {
int lineCount = 0;
Scanner scanner = null;
try {
scanner = new Scanner(new File(filePath));
while (scanner.hasNextLine()) {
System.out.println("文件内容: " + scanner.nextLine());
++lineCount;
}
} catch (Exception e) {
} finally {
if (scanner != null) {
scanner.close();
}
}
return lineCount;
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("行数: " + getLineCountOfFile("c:\\1.txt"));
}
public static int getLineCountOfFile(String filePath) {
int lineCount = 0;
Scanner scanner = null;
try {
scanner = new Scanner(new File(filePath));
while (scanner.hasNextLine()) {
System.out.println("文件内容: " + scanner.nextLine());
++lineCount;
}
} catch (Exception e) {
} finally {
if (scanner != null) {
scanner.close();
}
}
return lineCount;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询