导航:首页 > 编程语言 > javaexception显示行号

javaexception显示行号

发布时间:2023-05-20 00:03:08

『壹』 为什么java的NullPointerException不打出具体哪个变量是null只标出行号

你好,很高兴回答你的问题。
这个确实是java一个让人难受的地方。
不过销老从Java14开始空指信丛针异常信息有了更明确的描述,可以更方便地找到是哪个对滑斗樱象为null了。
如果有帮助到你,请点击采纳。

『贰』 想用java做个文本编辑器,能显示行号的那种,遇到问题了,望解决

看伏举看下面代码:水平动条滚动条隐藏,垂直滚动条自动腊腊出现。JTextArea setLineWrap(true);就会自动换行就轮厅滑会可以了。
public class Note extends JFrame {
public Note(){
JTextArea west=new JTextArea();
west.setLineWrap(true);

JTextArea txaDisplay = new JTextArea();
txaDisplay.setLineWrap(true);
JScrollPane scroll = new JScrollPane(txaDisplay);
scroll.setHorizontalScrollBarPolicy( //水平隐藏滚动条
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

scroll.setVerticalScrollBarPolicy( //垂直滚动条自动出现
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

add(scroll,BorderLayout.CENTER);
add(west,BorderLayout.WEST);

setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(300,100,400,400);

}
public static void main(String[] args) {
new Note();

}

}

『叁』 java记事本程序中显示行号的程序块

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;

public class ShowSourceCode {

public static void main(String[] args) throws FileNotFoundException, IOException{

RandomAccessFile file = new RandomAccessFile("野友戚Add.java", "告贺r"颂陵);
String tmp;

while((tmp = file.readLine()) != null){
System.out.println(tmp);
}

file.seek(0);

int lineNum = 1;
while((tmp = file.readLine()) != null){
System.out.println(lineNum + ": " + tmp);
lineNum++;
}
}

}

『肆』 如何在Java程序出现异常时输出其文件和行号

try {
。。。慧搭。。前衡拿
}
catch(Exception e) {
e.printStackTrace(); //打印出错stack信息, 包括class 和行拦桐号
}

『伍』 java编程工具,我的eclips左边怎么没有显示行数的数字啊怎么设置,谢谢。

eclipse中怎样显示行号
选择"窗口"->首选项->编辑器->文本编辑器->右边有"显示行号"->打勾就行了。

Window->Preferences->Editor->Text Editor->Display line numbers

或者 ctrl+F10 勾选show line Number 就是了!

别忘了采纳啊~~~~~

『陆』 java 读写文件异常怎么处理

publicclassReadFromFile{
/**
*以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
*/
(StringfileName){
Filefile=newFile(fileName);
InputStreamin=null;
try{
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
//一次读一铅纤个字节
in=newFileInputStream(file);
inttempbyte;
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
}
in.close();
}catch(IOExceptione){
e.printStackTrace();
return;
}
try{
System.out.println("以字节为单位读取文件内容,一次读多个字节:");
//一次读多个字节
byte[]tempbytes=newbyte[100];
intbyteread=0;
in=newFileInputStream(fileName);
陆雹ReadFromFile.showAvailableBytes(in);
//读入多个字节到字节数组中,byteread为一次读入的字节数
while((byteread=in.read(tempbytes))!=-1){
System.out.write(tempbytes,0,byteread);
}
}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以字符为单位读取文件,常用于读文本,数字等类型的文件
*/
(StringfileName){
Filefile=newFile(fileName);
Readerreader=null;
try{
System.out.println("以字符为单位读取文件内容,一次读一个字节:");
//一次读一个字符
reader=newInputStreamReader(newFileInputStream(file));
inttempchar;
while((tempchar=reader.read())!=-1){
//对于windows下, 这两个字符在一起时,表示一个换行。
//但如果这两个字符分开显示时,会换两次行。
//因此,屏蔽掉 ,或者屏蔽 。否则,将会多出很多空行。
if(((char)tempchar)!=' '){
System.out.print((char)tempchar);
}
}
reader.close();
}catch(Exceptione){
e.printStackTrace();
}
try{
System.out.println("以字符为单位读取文件内容,一次读多个字节:");
//一次读多个字符
char[]tempchars=newchar[30];
intcharread=0;
reader=newInputStreamReader(newFileInputStream(fileName));
//读入多个字符到字符数组中,charread为一次读取字符数
while((charread=reader.read(tempchars))!=-1){
//同样屏蔽掉 不显示
if((charread==tempchars.length)
&&(tempchars[tempchars.length-1]!=' ')){
System.out.print(tempchars);
}else{
for(inti=0;i<charread;i++){
if(tempchars[i]==' '){
continue;
早激帆}else{
System.out.print(tempchars[i]);
}
}
}
}

}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以行为单位读取文件,常用于读面向行的格式化文件
*/
(StringfileName){
Filefile=newFile(fileName);
BufferedReaderreader=null;
try{
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader=newBufferedReader(newFileReader(file));
StringtempString=null;
intline=1;
//一次读入一行,直到读入null为文件结束
while((tempString=reader.readLine())!=null){
//显示行号
System.out.println("line"+line+":"+tempString);
line++;
}
reader.close();
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*随机读取文件内容
*/
(StringfileName){
RandomAccessFilerandomFile=null;
try{
System.out.println("随机读取一段文件内容:");
//打开一个随机访问文件流,按只读方式
randomFile=newRandomAccessFile(fileName,"r");
//文件长度,字节数
longfileLength=randomFile.length();
//读文件的起始位置
intbeginIndex=(fileLength>4)?4:0;
//将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[]bytes=newbyte[10];
intbyteread=0;
//一次读10个字节,如果文件内容不足10个字节,则读剩下的字节。
//将一次读取的字节数赋给byteread
while((byteread=randomFile.read(bytes))!=-1){
System.out.write(bytes,0,byteread);
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(randomFile!=null){
try{
randomFile.close();
}catch(IOExceptione1){
}
}
}
}

/**
*显示输入流中还剩的字节数
*/
(InputStreamin){
try{
System.out.println("当前字节输入流中的字节数为:"+in.available());
}catch(IOExceptione){
e.printStackTrace();
}
}

publicstaticvoidmain(String[]args){
StringfileName="C:/temp/newTemp.txt";
ReadFromFile.readFileByBytes(fileName);
ReadFromFile.readFileByChars(fileName);
ReadFromFile.readFileByLines(fileName);
ReadFromFile.readFileByRandomAccess(fileName);
}
}

『柒』 如何在JAVA程序显示时每行添加行号

大概就是这样啦,换成你自己的文件名就祥肆行埋衡了

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;

public class ShowSourceCode {

public static void main(String[] args) throws FileNotFoundException, IOException{

RandomAccessFile file = new RandomAccessFile("Add.java", "r"谨液轿);
String tmp;

while((tmp = file.readLine()) != null){
System.out.println(tmp);
}

file.seek(0);

int lineNum = 1;
while((tmp = file.readLine()) != null){
System.out.println(lineNum + ": " + tmp);
lineNum++;
}
}

}

『捌』 如何在JAVA程序显示时每行添加行号(行号是按26个字母,不是数字顺序)

定义一个变量int row,用来统计当纳扰前行数,再用row%26+65(这是大写字蔽茄察母,小写的+97),再将得出的值转换成字符类型就可以宏茄了

『玖』 java eclipse如何显示行数

问题世档1:在编辑区最左边地方右键,选择“Show Line Numbers”就行了。
问题2:搜并乱快捷键(ctrl+f)
问题蔽贺3:在工程名上右键,选择“Refactor->Rename”。
希望对你有帮助!

阅读全文

与javaexception显示行号相关的资料

热点内容
导出手机qq文件到u盘 浏览:456
电脑如何打开ppt文件怎么打开方式 浏览:782
魅族锁定区文件夹 浏览:357
刻字cnc怎么编程 浏览:182
学校的网络拓扑结构图 浏览:784
收集100个pdf文件里关键词 浏览:594
苹果关闭4g网络设置 浏览:289
如何监测数据库 浏览:967
拷贝过来的pdf文件 浏览:751
抖音小店的访客数据怎么看 浏览:670
怎么把c语言编程的字符向下移动 浏览:786
sql删除文件组代码 浏览:978
安卓post请求多重json 浏览:776
微信消除数据怎么恢复 浏览:918
小米刷机显示系统找不到指定文件 浏览:528
苹果手机小风扇图app叫什么 浏览:292
繁体中文输入工具 浏览:916
pc桌面壁纸文件夹 浏览:473
微信怎么添加群 浏览:781
40岁男人适合的微信名 浏览:925

友情链接