RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何通过java代码获取 java怎么获取uuid

如何通过Java代码获取tomcat服务器的绝对路径

//也许有你想要的,前提是在项目布署运行起来后,在servlet中或controller中运行以下代码即可。

涡阳网站建设公司创新互联,涡阳网站设计制作,有大型网站制作公司丰富经验。已为涡阳超过千家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的涡阳做网站的公司定做!

System.out.println(this.getClass().getResource("/"));//结果:file:/E:/work/service/tomcat7.0.65/webapps/mvc_adminlte/WEB-INF/classes/

System.out.println(System.getProperty("catalina.home"));//结果:E:\work\service\tomcat7.0.65

System.getProperty("user.dir");//结果:E:\work\service\tomcat7.0.65\bin

System.out.println(request.getSession().getServletContext().getRealPath("/"));//结果:E:\work\service\tomcat7.0.65\webapps\你的项目名称\

希望能帮到你!

怎样用java代码获取txt文本的指定值

[Java] view plain copy

import java.io.*;

public class hh {

/**

* @param args

*/

public static void main(String[] args) {

// 指定读取的行号

int lineNumber = 2;

// 读取文件

//File sourceFile = new File("D:/java/test.txt");

File sourceFile = new File("C://TEXT.txt");

try {

// 读取指定的行

readAppointedLineNumber(sourceFile, lineNumber);

// 获取文件的内容的总行数

System.out.println(getTotalLines(sourceFile));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

// 读取文件指定行。

static void readAppointedLineNumber(File sourceFile, int lineNumber)

throws IOException {

FileReader in = new FileReader(sourceFile);

LineNumberReader reader = new LineNumberReader(in);

String s = "";

if (lineNumber = 0 || lineNumber getTotalLines(sourceFile)) {

System.out.println("不在文件的行数范围(1至总行数)之内。");

System.exit(0);

}

int lines = 0;

while (s != null) {

lines++;

s = reader.readLine();

if((lines - lineNumber) == 0) {

System.out.println(s);

System.exit(0);

}

}

reader.close();

in.close();

}

// 文件内容的总行数。

static int getTotalLines(File file) throws IOException {

FileReader in = new FileReader(file);

LineNumberReader reader = new LineNumberReader(in);

String s = reader.readLine();

int lines = 0;

while (s != null) {

lines++;

s = reader.readLine();

if(lines=2){

if(s!=null){

System.out.println(s+"$");

}

}

}

reader.close();

in.close();

return lines;

}

}

如何使用Java代码获取播放文件的时长

java中直接使用AudioInputStream类来操作音乐文件,获取时长,实例如下:

import java.io.File;

import java.io.IOException;

import javax.sound.sampled.AudioInputStream;

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.Clip;

import javax.sound.sampled.LineUnavailableException;

import javax.sound.sampled.UnsupportedAudioFileException;

public class AudioLength {

public static void main(String[] args) throws LineUnavailableException,

UnsupportedAudioFileException, IOException {

File file = new File("d:/test.wav");

Clip clip = AudioSystem.getClip();

AudioInputStream ais = AudioSystem.getAudioInputStream(file);

clip.open(ais);

System.out.println( clip.getMicrosecondLength() / 1000000D + " s" );//获取音频文件时长

}

}


网页名称:如何通过java代码获取 java怎么获取uuid
浏览地址:http://sczitong.cn/article/dogihgi.html