首页 > 其他分享 >代码运行截图

代码运行截图

时间:2022-11-04 21:55:19浏览次数:56  
标签:截图 String System 代码运行 println new public out

1.

import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class createFile {
public static void main(String[] args) {

}
//方法1
@Test
public void create01(){

String pathname ="D://陈志烨20215220608文件一.txt";

File file = new File(pathname);

try {
file.createNewFile();
System.out.println("创建文件一成功");
} catch (IOException e) {
throw new RuntimeException(e);
}


}
@Test
//方法二
public void create02(){
// String pathname="D://";
File parentFile=new File("D://");

String fileName="陈志烨20215220608文件二.txt";

File file=new File(parentFile,fileName);

try {
file.createNewFile();
System.out.println("创建文件二成功");
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Test
public void create03(){
String parentPath="D://";
String filePath="陈志烨20215220608文件三.txt";

File file=new File(parentPath,filePath);

try {
file.createNewFile();
System.out.println("创建文件三成功");
} catch (IOException e) {
throw new RuntimeException(e);
}
}


}

 

 

 

 

 

 

 

 

 

 

 

 2.

import org.testng.annotations.Test;

import java.io.File;

public class FileInformation {
public static void main(String[] args) {

}
//获取文件信息
@Test
public void Info(){
//先创建文件对象
File file=new File("D://陈志烨20215220608文件一.txt");

//调用相应方法,得到对应信息
System.out.println("文件名称:"+file.getName());

System.out.println("文件绝对路径:"+file.getAbsolutePath());

System.out.println("文件父目录:"+file.getParent());

System.out.println("文件大小(字节)"+file.length());

System.out.println("文件是否存在:"+file.exists());

System.out.println("是否是文件:"+file.isFile());

System.out.println("是否是目录:"+file.isDirectory());
}

}

 

 

3.

import org.testng.annotations.Test;

import java.io.File;

public class fileDirectory {
public static void main(String[] args) {

}
@Test
//删除文件
public void fileDelete(){
String filePath="D://陈志烨20215220608文件一.txt";
File file=new File(filePath);
if (file.exists()){
if (file.delete()){
System.out.println(filePath+"删除成功");
}else {
System.out.println(filePath+"删除失败");
}
}else {
System.out.println("文件不存在");
}
}
//输出目录
@Test
public void fileDeleteD(){
String filePath="D://陈志烨20215220608.txt";
File file=new File(filePath);
if (file.exists()){
if (file.delete()){
System.out.println(filePath+"删除成功");
}else {
System.out.println(filePath+"删除失败");
}
}else {
System.out.println("目录不存在");
}


}

//判断目录是否存在,不存在就创建
@Test
public void fileDeleteD1(){
String dirPath="D://text//陈志烨20215220608dir1.txt";
File file=new File(dirPath);
if (file.exists()){
System.out.println(dirPath+"该目录已经存在");
}else {
if (file.mkdir()){
System.out.println("创建成功");
}else {
System.out.println("创建失败");
}
}
}

}

 

 

 

 

 

 

 

 

4.

import java.util.Scanner;

public class scanPrintTest {
public static void main(String[] args) {
//创建Scanner对象,接受从控制台输入
Scanner input =new Scanner(System.in);
//接受String类型
String str =input.next();
//输出结果
System.out.println(str);

System.out.println("hellow world");
}
}

 

 

 

import java.util.Scanner;

public class scanTest {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
//double类型的数据
System.out.println("请输入一个double类型的数");
double d=input.nextDouble();
System.out.println(d);
//int类型的数据
System.out.println("请输入一个int类型的数");
int i=input.nextInt();
System.out.println(i);
//字符串类型的数据
System.out.println("请输入一个string类型的数");
String s=input.next();
System.out.println(s);


}
}

 

 

 5.

import org.testng.annotations.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class fileInputStream {
public static void main(String[] args) {

}
@Test
public void fileIn1(){
String filePath="D://陈志烨20215220608file.txt";
int readData;
FileInputStream fileInputStream=null;

try {
//创建FileInputStream对象,用于读取文件
fileInputStream=new FileInputStream(filePath);

while ((readData=fileInputStream.read())!=-1){
System.out.println((char)readData);
}
} catch (IOException e) {
throw new RuntimeException(e);
}finally {
//关闭文件流
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@Test
public void fileIn2(){
String filePath="D://陈志烨20215220608file.txt";
int readData;
int readlength=0;
//字节数组
byte[] buf =new byte[8];
FileInputStream fileInputStream=null;
try {
//创建FileInputStream对象,用于读取文件
fileInputStream=new FileInputStream(filePath);

while ((readlength=fileInputStream.read(buf))!=-1){
System.out.println(new String(buf,0,readlength));
}

} catch (IOException e) {
throw new RuntimeException(e);
}finally {
//关闭文件流
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@Test
public void fileIn3(){
String filePath="D://陈志烨20215220608file.txt";
int readData;
int readlength=0;
//字节数组
byte[] buf =new byte[8];
FileInputStream fileInputStream=null;
try {
//创建FileInputStream对象,用于读取文件
fileInputStream=new FileInputStream(filePath);
while ((readlength=fileInputStream.read(buf))!=-1){
System.out.println(new String(buf,0,readlength));
}
} catch (IOException e) {
throw new RuntimeException(e);
}finally {
//关闭文件流
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

}

}

 

 

 

 

6.

import org.testng.annotations.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class outputStream {
public static void main(String[] args) {

}
//使用FileOutputStream将数据写到文件中
//如果文件不存在,则创建文件
@Test
public void writeFile(){
String filePath="D://陈志烨20215220608fileout.txt";
//创建对象
FileOutputStream fileOutputStream=null;
try {
fileOutputStream=new FileOutputStream(filePath);

//写入一个字节
//fileOutputStream.write('H');

//写入一个字符串
// String str="hello socket";
// str.getBytes()//将字符串转换为字节数组
// fileOutputStream.write(str.getBytes());

//写入字符串
String str ="hello lst";
fileOutputStream.write(str.getBytes(),0,str.length());

} catch (IOException e) {
throw new RuntimeException(e);
}finally {
try {
fileOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}

 

 

7.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class copyPic {
//file读和写实现复制文件
public static void main(String[] args)throws Exception {
//创建file对象
File f=new File("D://test.jpg");
//判断文件是否存在
if (f.exists()){
System.out.println("test.jpg存在,可以复制");
}else {
f.createNewFile();
System.out.println("test.jpg不存在,新建成功,可以复制");
}
//创建FileInputStream对象
FileInputStream inp=new FileInputStream(f);


File f1=new File("d://demo");
if (f1.isDirectory()){
FileOutputStream out=new FileOutputStream("d://demo//"+f.getName());
byte bytes[]=new byte[1024];
int temp=0;
while ((temp=inp.read(bytes))!=-1){
out.write(bytes,0,temp);
}
//结束
inp.close();
out.close();
System.out.println("文件拷贝成功");
}else {
f1.mkdir();
System.out.println("demo目录不存在,已经创建成功,继续复制");
FileOutputStream out=new FileOutputStream(":d://demo//"+f.getName());
byte bytes[]=new byte[1024];
int temp=0;
while ((temp=inp.read(bytes))!=-1){
out.write(bytes,0,temp);
}
//结束
inp.close();
out.close();
System.out.println("文件拷贝成功");


}

}
}

 

 

 

标签:截图,String,System,代码运行,println,new,public,out
From: https://www.cnblogs.com/chenzhiye1845/p/16859235.html

相关文章

  • 博主制作的DevExpress For D7 的自动汉化安装包[软件截图]
     博主制作的DevExpressForD7的自动汉化安装包,汉化前请先安装DevExpress3.22英文原版。  软件简介:每次重装Delphi7都要安装DevExpress3.22,以前为了给DevExpress进......
  • ait+s截图保存到桌面
    !s::Send{LShift}+{LWindown}+{S}+{LWinup}Sleep5000Gdip_CaptureClipboard(A_Desktop"/"A_MM"-"A_DD""A_Hour"-"A_Min".jpg",100);剪贴板图片保存Gd......
  • Java实现HTML页面截图功能
    概述业务开发中,经常会有HTML页面截图,或打印另存为PDF文件的需求。本文即是HTML页面截图需求的技术调研过程的成文。不想看长篇大论的同学,可以直接看Selenium部分,本人最后也......
  • js截图功能
     //setTimeout(()=>{////获取要导出的DOM//constrect=document.getElementById('iklDetailAll').getBoundingClientRect()//html2c......
  • selenium-截图
    fromwebdriver_helperimportwebdriver,get_webdriverfromselenium.webdriverimportchromedriver=webdriver.Chrome()#实例化,刚启动浏览器是空白页面dr......
  • 【C语言游戏】三子棋完整代码和正确结果截图
    ......
  • Vue笔记2 v-bind,截图软件snipaste、computed
                                              ......
  • 一、注册失败截图处理-20
    1、D:\imooc\selenium\register_function.py#功能:在register_code.py的基础上,进行二次改造。#编码格式#coding=utf-8#添加当前项目路径importsyssys.path.app......
  • 优秀 截图 软件 (电脑必备)
    简单说明只要用电脑,它就应该是必备软件。大猫录课时,非常频繁的借助了该软件,我极少这样形容一个软件,除非它对我帮助很大功能 演示1.开始截图(快捷键F1)如果觉得不合适,可......
  • 网页截图并添加文字、图片
    安装依赖yarnaddhtml2canvas实现代码toImage(){ //手动创建一个canvas标签 constcanvas=document.createElement("canvas") //获取父标签,意思是这个标签内......