我正在努力寻找解决方案,为什么我的程序不能在Windows上运行。
我在Ubuntu 16.04
上进行了测试,一切正常。我的朋友在Mac
上测试了它并再次测试了相同的结果 - 工作。
我的第一个想法是 - 错误的道路。但路径还可以,我们测试了它。问题可能是Windows无法创建文件。我评论了其他代码,甚至没有创建txt。
我很乐意回答每一个问题。抱歉我的英文和我的代码:)
替换课程:
package model;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
/**
*
* @author pepek
*/
public class Replace {
public static void replaceInFile(String fileName) throws IOException {
File file = new File(fileName);
// fileName = "/home/pepek/Desktop/Share/09a_pozice_asic_pcb.txt";
File tempFile = File.createTempFile("buffer", ".tmp");
FileWriter fw = new FileWriter(tempFile);
Reader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while(br.ready()) {
fw.write(br.readLine().replace(".", ",") +"\n");
}
fw.close();
br.close();
fr.close();
// Finally replace the original file.
tempFile.renameTo(file);
}
}
Okno班级:
package gui;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import model.Replace;
/**
*
* @author pepek
*/
public class Okno extends JFrame {
private JButton btnGlass;
public Okno() {
setLayout(new GridLayout(0,2));
btnGlass = new JButton("Pozice skla");
btnGlass.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\02_pozice_skla\\02_pozice_skla_data_new.txt");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnGlass);
JButton btnElement = new JButton("Pozice elementu");
btnElement.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\05_pozice_elementu\\05_pozice_elementu.TXT");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnElement);
JButton btnFireElement = new JButton("Vytvrzení elementu");
btnFireElement.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\07_pozice_elementu_vytvrdnuti\\07_pozice_elementu_vytvrdnuti_data.TXT");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnFireElement);
JButton btnUhelSpaceru = new JButton("Úhel spaceru");
btnUhelSpaceru.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\08_uhel_spaceru\\08_uhel_spaceru.TXT");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnUhelSpaceru);
JButton btnPozice = new JButton("Pozice ASIC a PCB");
btnPozice.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\09a_pozice_asic_pcb\\09a_pozice_asic_pcb.TXT");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnPozice);
JButton btnVyska = new JButton("Výška ASIC a PCB");
btnVyska.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\10a_vyska_asic_pcb\\10a_vyska_asic_pcb.txt");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnVyska);
JButton btnVyskaSpaceru = new JButton("Vytvrzení elementu");
btnVyskaSpaceru.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Replace.replaceInFile("D:\\merove programy\\15_vyska_spaceru\\15_vyska_spaceru.txt");
} catch (IOException ex) {
Logger.getLogger(Okno.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
add(btnVyskaSpaceru);
setTitle("Find&Replace App"); // "super" Frame sets its title
setSize(750, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Okno();
}
}
答案 0 :(得分:-1)
尝试更改路径以使用反斜杠或双反斜杠(反斜杠被视为特殊字符),因为<WebView NavigationStarting="OnNavigationStarting" />
void OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
var url = args.Uri;
if(url.Scheme == "myprotocol")
{
// navigating to my custom uri, cancelling...
args.Cancel = true;
}
}
在其路径中使用反斜杠windows
1}}和linux
使用正斜杠