vscode整個(gè)項(xiàng)目被刪除,如果恢復(fù)!

如果你的項(xiàng)目所有的文件都被vscode編輯過,并且這項(xiàng)目編輯時(shí)間短暫.那么還有激活挽救

這里是我使用java恢復(fù)的一個(gè)代碼.我急著恢復(fù)自己的代碼,代碼簡(jiǎn)陋,不過可以參考


```java

package cn.cosoc.webscreenshot;

import com.alibaba.fastjson.JSONArray;

import com.alibaba.fastjson.JSONObject;

import com.alibaba.fastjson.JSONReader;

import org.apache.commons.io.FileUtils;

import org.junit.jupiter.api.Test;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

class FileInfoimplements Comparable{

public Stringid;

? public long timestamp;

? ? public StringgetId() {

return id;

? ? }

public void setId(String id) {

this.id = id;

? ? }

public long getTimestamp() {

return timestamp;

? ? }

public void setTimestamp(long timestamp) {

this.timestamp = timestamp;

? ? }

@Override

? ? public StringtoString() {

return "FileInfo{" +

"id='" +id +'\'' +

", timestamp=" +timestamp +

'}';

? ? }

@Override

? ? public int compareTo(FileInfo o) {

if (this.getTimestamp() - o.getTimestamp() >0) {

return? -1;

? ? ? ? }

if (this.getTimestamp() - o.getTimestamp() <0) {

return? 1;

? ? ? ? }

return 0;

? ? }

}

//@SpringBootTest

class ApplicationTests {

@Test

? ? void test ()throws IOException {

File srcFile =new File("/home/hzhzhzh/.config/Code/User/History");

? ? ? ? getAllFilePath(srcFile);

? ? }

void getAllFilePath( File srcFile)throws IOException {

//獲取給定的File目錄下所有文件或者目錄下的所有File數(shù)組

? ? ? ? File[] fileArray = srcFile.listFiles();

? ? ? ? for (File file : fileArray){

// 判斷File對(duì)象是否為目錄

? ? ? ? ? ? if(file.isDirectory()){

String path = file.getPath();

? ? ? ? ? ? ? ? // entries

? ? ? ? ? ? ? ? String entriesPath = path +"/entries.json";

? ? ? ? ? ? ? ? File temp =new File(entriesPath);

? ? ? ? ? ? ? ? // 如果存在

? ? ? ? ? ? ? ? if (temp.exists()) {

JSONReader jsonReader = getJsonReader(entriesPath);

? ? ? ? ? ? ? ? ? ? JSONObject jsonObject = jsonReader.readObject(JSONObject.class);

? ? ? ? ? ? ? ? ? ? String resource =? jsonObject.getString("resource");

? ? ? ? ? ? ? ? ? ? if (resource.contains("/home/hzhzhzh/Development/WebProject/web-screenshot-chrome-plugin/")) {

// 獲取文件記錄

? ? ? ? ? ? ? ? ? ? ? ? JSONArray entries =? jsonObject.getJSONArray("entries");

? ? ? ? ? ? ? ? ? ? ? ? List fileInfos =new ArrayList<>();

? ? ? ? ? ? ? ? ? ? ? ? for (int i =0; i < entries.size(); i++) {

JSONObject jsonObject1 = entries.getJSONObject(i);

? ? ? ? ? ? ? ? ? ? ? ? ? ? long? timestamp1 = jsonObject1.getLongValue("timestamp");

? ? ? ? ? ? ? ? ? ? ? ? ? ? String? id = jsonObject1.getString("id");

? ? ? ? ? ? ? ? ? ? ? ? ? ? FileInfo fileInfo =new FileInfo();

? ? ? ? ? ? ? ? ? ? ? ? ? ? fileInfo.setId(id);

? ? ? ? ? ? ? ? ? ? ? ? ? ? fileInfo.setTimestamp(timestamp1);

? ? ? ? ? ? ? ? ? ? ? ? ? ? fileInfos.add(fileInfo);

? ? ? ? ? ? ? ? ? ? ? ? }

Collections.sort(fileInfos);

? ? ? ? ? ? ? ? ? ? ? ? // 獲取最新的一個(gè)

? ? ? ? ? ? ? ? ? ? ? ? FileInfo fs = fileInfos.get(0);

? ? ? ? ? ? ? ? ? ? ? ? // 需要恢復(fù)的文件

? ? ? ? ? ? ? ? ? ? ? ? String restoreF = path +"/" + fs.getId();

? ? ? ? ? ? ? ? ? ? ? ? // 需要恢復(fù)的路徑

? ? ? ? ? ? ? ? ? ? ? ? String restoreP = resource.replace("file:///home/hzhzhzh/Development/WebProject/","/tmp/");

? ? ? ? ? ? ? ? ? ? ? ? FileUtils.copyFile(new File(restoreF), new File(restoreP));

? ? ? ? ? ? ? ? ? ? }

}

}else {

//獲取絕對(duì)路徑輸出在控制臺(tái)

? ? ? ? ? ? ? ? System.out.println(file.getAbsoluteFile());

? ? ? ? ? ? }

}

}

/**

? ? * 獲取JSONReader

? ? * @param srcPath

? ? * @return

? ? */

? ? private JSONReadergetJsonReader(String srcPath) {

JSONReader jsonReader =null;

? ? ? ? try {

FileReader fileReader=new FileReader(srcPath);

? ? ? ? ? ? jsonReader =new JSONReader(fileReader);

? ? ? ? }catch (FileNotFoundException e) {

e.printStackTrace();

? ? ? ? }

return jsonReader;

? ? }

}

```

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容