
正文
java阅读软件代码 阅读java版
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java语言框架编写小说阅读器代码
int option = -1;
Object options[] = { "Yes", "No" };
option = JOptionPane.showOptionDialog(frame, "是否退出阅读?", "exit",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
switch (option) {
case JOptionPane.YES_OPTION:
System.exit(0);
}
}
相关问答
Q1: 如何阅读 Java 开源代码
准备好环境,比如安装好Eclipse,IDEA等你喜欢的集成开发环境
准备好Maven环境
创建一个项目,把你要研究的开源项目pom引入进来
使用maven把源代码下载下来
写一个简单的例子使用开源代码
分析从启动开始,断点调试,看看调用了哪些方法,每个方法是怎么实现的
所有方法都断点了一遍,你在这个过程中实际上已经了解了开源代码是怎么实现具体功能的了
Q2: 北大青鸟java培训:提高代码阅读能力的技巧有哪些?
对于学习软件开发的人来说,学会阅读源代码是非常重要的,然而很多人并不具备阅读源代码的能力。
很多人不喜欢阅读源代码,认为这是非常无聊的事情。
如果不会阅读源代码,对于后面写代码是非常困难的,很多开发人员主要把重心放在写代码上,反而忽略代码的阅读。
阅读代码是非常关键的,下面天津电脑培训为大家介绍阅读代码的技巧。
1、学会运行代码运行代码是阅读代码的第一步,这样能够了解关于项目的很多细节,并且了解怎么进行运行,掌握库的使用方法。
这样是了解一个项目最好的方法,如果能够自己了解和编写相关的项目,这样对于使用框架和库会有自己的想法。
2、找到高层次的逻辑当您开始阅读项目的代码时,会涉及到每个细节。
相反的,你还需要掌握高层次结构,从这个地方找到入口点,在很多大型项目开发中都可以使用这种方法。
如果是进行web程序开发,那么天津IT培训建议应该查看不同的包,例如存储业务逻辑的位置,存储UI代码的位置,控制器所在的位置等等。
3、了解和使用工具很多工具都可以有助于源代码阅读,并且对可视化代码有很大的帮助。
在使用过程中,天津IT培训认为IntelliJIdea工具能够导航源代码,允许使用单词的一部分,甚至单词的缩写进行搜索。
您还应该学习键盘的快捷键。
使用鼠标导航源代码可能会非常无聊和缓慢,键盘快捷键可以更快的进行跳转。
4、了解语言更深入地了解特定语言有助于提高您的代码阅读技能。
每种语言都有自己的约定,样式和语法。
这些知识可以帮助您快速熟悉特定代码。
其中天津电脑培训发现在Java语言中,方法名称以小写字母开头,而在C#语言中,方法名称以大写字母开头。
了解这种差异可以帮助你从源代码中找到识别方法。
Q3: JAVA阅读源码,大量英文注释阅读不方便,求集成idea里面的翻译java注释由英文翻译为中文的工具。
学会在idea(eclipse)中阅读、调试源码,是java程序员必不可少的一项技能。
在idea中配完环境后,默认其实也是能够对jdk的源码进行debug调试的。但是无法在源码中添加自己的注释,无法添加自己的理解。如果干瞪眼看的话,可能过段时间,就忘记了。下面就介绍下,如何在jdk源码中为所欲为,像在我们自己的代码中一样写注释、调代码:
打开idea,选择Project-File-Project Structure-SDKs-Sourcepath,初始状态如下图 :
打开本地jdk安装路径,本处为E:\java\jdk8,将此路径下的src.zip压缩包解压到自定义的指定文件夹(可以在电脑磁盘任意位置),本处解压到同目录的jdk_source文件夹下,如下图:
继续在步骤1中的设置页面中操作,将E:\java\jdk8\src.zip通过右侧的减号将其移除;并通过右侧的加号,将解压文件夹E:\java\jdk8\jdk_source导入进来;点击apply,再点击OK。导入结果见下图:
这时,再重新打开jdk的源码类,我们就可以在源java文件中,添加自己的注释了。
一定注意:添加注释时,一定不要新加一行写注释。最好在一行代码的后面,使用//进行注释。否则行号和真正的jre中编译后的代码行号对应不上,如果对源码debug时,会出现代码运行和行号不匹配的情况
Q4: JAVA如何阅读代码更高效?
个人经验,
读文件有4种方法,
1 按行读
2 按规定大小字节读
3 按流读
4 随机读取文件
我认为第3种是最好的,而且他是通吃的,
下面是我从网上找来的,你看看有用吗?
====================================
前两天用到读写文件的操作,上网搜了一些这方面的资料。很有用的。
java中多种方式读文件
一、多种方式读文件内容。
1、按字节读取文件内容
2、按字符读取文件内容
3、按行读取文件内容
4、随机读取文件内容
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
public class ReadFromFile {
/**
* 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
* @param fileName 文件的名
*/
public static void readFileByBytes(String fileName){
File file = new File(fileName);
InputStream in = null;
try {
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
// 一次读一个字节
in = new FileInputStream(file);
int tempbyte;
while((tempbyte=in.read()) != -1){
System.out.write(tempbyte);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
try {
System.out.println("以字节为单位读取文件内容,一次读多个字节:");
//一次读多个字节
byte[] tempbytes = new byte[100];
int byteread = 0;
in = new FileInputStream(fileName);
ReadFromFile.showAvailableBytes(in);
//读入多个字节到字节数组中,byteread为一次读入的字节数
while ((byteread = in.read(tempbytes)) != -1){
System.out.write(tempbytes, 0, byteread);
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (in != null){
try {
in.close();
} catch (IOException e1) {
}
}
}
}
/**
* 以字符为单位读取文件,常用于读文本,数字等类型的文件
* @param fileName 文件名
*/
public static void readFileByChars(String fileName){
File file = new File(fileName);
Reader reader = null;
try {
System.out.println("以字符为单位读取文件内容,一次读一个字节:");
// 一次读一个字符
reader = new InputStreamReader(new FileInputStream(file));
int tempchar;
while ((tempchar = reader.read()) != -1){
//对于windows下,rn这两个字符在一起时,表示一个换行。
//但如果这两个字符分开显示时,会换两次行。
//因此,屏蔽掉r,或者屏蔽n。否则,将会多出很多空行。
if (((char)tempchar) != 'r'){
System.out.print((char)tempchar);
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("以字符为单位读取文件内容,一次读多个字节:");
//一次读多个字符
char[] tempchars = new char[30];
int charread = 0;
reader = new InputStreamReader(new FileInputStream(fileName));
//读入多个字符到字符数组中,charread为一次读取字符数
while ((charread = reader.read(tempchars))!=-1){
//同样屏蔽掉r不显示
if ((charread == tempchars.length)(tempchars[tempchars.length-1] != 'r')){
System.out.print(tempchars);
}else{
for (int i=0; icharread; i++){
if(tempchars[i] == 'r'){
continue;
}else{
System.out.print(tempchars[i]);
}
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
}finally {
if (reader != null){
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
/**
* 以行为单位读取文件,常用于读面向行的格式化文件
* @param fileName 文件名
*/
public static void readFileByLines(String fileName){
File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
//一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null){
//显示行号
System.out.println("line " + line + ": " + tempString);
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null){
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
/**
* 随机读取文件内容
* @param fileName 文件名
*/
public static void readFileByRandomAccess(String fileName){
RandomAccessFile randomFile = null;
try {
System.out.println("随机读取一段文件内容:");
// 打开一个随机访问文件流,按只读方式
randomFile = new RandomAccessFile(fileName, "r");
// 文件长度,字节数
long fileLength = randomFile.length();
// 读文件的起始位置
int beginIndex = (fileLength 4) ? 4 : 0;
//将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[] bytes = new byte[10];
int byteread = 0;
//一次读10个字节,如果文件内容不足10个字节,则读剩下的字节。
//将一次读取的字节数赋给byteread
while ((byteread = randomFile.read(bytes)) != -1){
System.out.write(bytes, 0, byteread);
}
} catch (IOException e){
e.printStackTrace();
} finally {
if (randomFile != null){
try {
randomFile.close();
} catch (IOException e1) {
}
}
}
}
/**
* 显示输入流中还剩的字节数
* @param in
*/
private static void showAvailableBytes(InputStream in){
try {
System.out.println("当前字节输入流中的字节数为:" + in.available());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String fileName = "C:/temp/newTemp.txt";
ReadFromFile.readFileByBytes(fileName);
ReadFromFile.readFileByChars(fileName);
ReadFromFile.readFileByLines(fileName);
ReadFromFile.readFileByRandomAccess(fileName);
}
}
二、将内容追加到文件尾部
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* 将内容追加到文件尾部
*/
public class AppendToFile {
/**
* A方法追加文件:使用RandomAccessFile
* @param fileName 文件名
* @param content 追加的内容
*/
public static void appendMethodA(String fileName,String content){
try {
// 打开一个随机访问文件流,按读写方式
RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
// 文件长度,字节数
long fileLength = randomFile.length();
//将写文件指针移到文件尾。
randomFile.seek(fileLength);
randomFile.writeBytes(content);
randomFile.close();
} catch (IOException e){
e.printStackTrace();
}
}
/**
* B方法追加文件:使用FileWriter
* @param fileName
* @param content
*/
public static void appendMethodB(String fileName, String content){
try {
//打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
FileWriter writer = new FileWriter(fileName, true);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String fileName = "C:/temp/newTemp.txt";
String content = "new append!";
//按方法A追加文件
AppendToFile.appendMethodA(fileName, content);
AppendToFile.appendMethodA(fileName, "append end. n");
//显示文件内容
ReadFromFile.readFileByLines(fileName);
//按方法B追加文件
AppendToFile.appendMethodB(fileName, content);
AppendToFile.appendMethodB(fileName, "append end. n");
//显示文件内容
ReadFromFile.readFileByLines(fileName);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------
写入文件
try{
FileWriter fw=new FileWriter(SystemConfig.getRealPath()+"WEB-INF/url.txt");
fw.write("movie"+name);
fw.close();
}catch(IOException e){
e.printStackTrace();
}
读文件中内容
try{
FileReader fr = null;
fr = new FileReader(SystemConfig.getRealPath()+"WEB-INF/url.txt");
BufferedReader br=new BufferedReader(fr);
String Line = null;
Line = br.readLine();
while(Line!=null){
s=Line;
Line=null;
br.close();
fr.close();
}
}catch(IOException e1){
e1.printStackTrace();
}
上传文件
try {
InputStream stream = getUpFile().getInputStream();//把文件读入
OutputStream bos = new FileOutputStream(filePath + "movie" +name);//建立一个上传文件的输出流
int bytesRead = 0;
byte[] buffer = new byte[1026];
while ( (bytesRead = stream.read(buffer, 0, 1026)) != -1) {
bos.write(buffer, 0, bytesRead);//将文件写入服务器
}
bos.close();
stream.close();
}catch(Exception e){
System.err.print(e);
}
java阅读软件代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于阅读java版、java阅读软件代码的信息别忘了在本站进行查找喔。





